%%-----------------------------------------------------------------------%%
%%--- The Integral ------------------------------------------------------%%

\chapter{The Integral}

Differential calculus starts with a simple geometric problem: given a
curve and a line tangent to that curve, find the slope of the line.
The subject then develops techniques used in solving this problem into
a combination of theory about derivatives and their properties,
techniques for calculating derivatives, and applications of
derivatives. This book begins the development of integral calculus and
starts with the simple geometric idea of area. This idea will be
developed into another combination of theory, techniques, and
applications. The integral will be presented in two completely
different ways: as a limit of \emph{Riemann sums}; and as an
\emph{inverse} of differentiation, also known as
\emph{antiderivative}. Conceptually, the limit approach to the
integral is geometric or numerical, while the antiderivative approach
is somewhat more algebraic.

One of the most important results in mathematics, The Fundamental
Theorem of Calculus, appears in this chapter. It connects these two
notions of the integral and also provides a relationship between
differential and integral calculus. Historically, this theorem marked
the beginning of modern mathematics, and it provided important tools
for the growth and development of the sciences. The chapter begins
with a look at area, some geometric properties of areas, and some
applications. First, we will see ways of approximating the areas of
regions such as tree leaves that are bounded by curved edges, and the
areas of regions bounded by graphs of functions. Then we will find
ways to calculate exactly the areas of some of these regions. Finally,
we will explore more of the rich variety of uses of areas. The primary
purpose of this introductory section is to help develop your intuition
about areas and your ability to reason using geometric arguments about
area. This type of reasoning will appear often in the rest of this
book and is very helpful for applying the ideas of calculus.


%%-----------------------------------------------------------------------%%
%%--- Integrals as areas ------------------------------------------------%%

\section{Integrals as areas}
\index{integral!as area}

We know from previous experience how to compute the areas of simple
geometrical shapes like triangles, circles, and rectangles. Formulas
for these have been known since the days of the ancient Greeks. But
how do you find the area under a more complicated curve such as
$y = x^2$ where $-1 < x < 1$? First, let's graph the function using
\sage as follows\footnote{
  Feel free to try this yourself, changing $a$, $b$ and $x^2$ to
  something else if you like.
}:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: a = -1; b = 1
sage: f = lambda x: x^2
sage: Lb = [[b, f(b)], [b, 0], [a, 0], [a, f(a)]]
sage: Lf = [[i / 20, f(i / 20)] for i in xrange(20*a, 20*b + 1)]
sage: P = polygon(Lf + Lb, rgbcolor=(0.2, 0.8, 0))
sage: Q = plot(f(x), x, a - 0.5, b + 0.5)
sage: show(P + Q)
\end{lstlisting}
\end{center}
%
This results in a plot similar to that shown in
Figure~\ref{fig:integral:area_quadratic}.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=2,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% graph of functions
\filldraw[fill=gray!25,color=gray!25]
(-1,0) -- plot[domain=-1:1] function{x**2} -- (1,0);
\draw[linestyle] plot[domain=-1.3:1.3] function{x**2};
% horizontal and vertical axes
\draw[axisstyle] (-1.5,0) -- (1.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.2) -- (0,2) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.05) node[below]{1} -- (1,0.05);
\draw[linestyle] (-1,-0.05) node[below]{$-1$} -- (-1,0.05);
% tick marks on vertical axis
\draw[linestyle] (-0.05,1) node[left]{1} -- (0.05,1);
\end{tikzpicture}
\caption{Plot of $y = x^2$ for $-1 \leq x \leq 1$.}
\label{fig:integral:area_quadratic}
\end{figure}

The rough, general idea introduced in this section is the following.
To compute the area of the complicated shaded region in
Figure~\ref{fig:integral:area_quadratic}, we break it up into
\emph{lots} of simpler subregions, whose areas are easy to
compute. Then we add up the areas of the subregions to get the total
area. We shall return to this example later.

The basic shape we will use is the rectangle, whose area is given by
the formula\index{rectangle area formula}
\[
\text{area}
=
\text{base} \times \text{height}
\]
If the units for each side of the rectangle are ``meters,'' then the
area will have the units
``meters'' $\times$ ``meters'' $=$ ``square meters'' $=$ $m^2$. Other
area formulas needed for this section are: the area formula for
triangles\index{triangle area formula}
%
\begin{equation}
\label{eq:integral:area_triangle}
\text{area}
=
bh / 2
\end{equation}
%
where $b$ is the length of the base and $h$ is the height. The
corresponding formula for circles is\index{circle area formula}
\[
\text{area}
=
\pi r^2
\]
with $r$ being the radius. We also assume the following familiar
properties of area:

\begin{itemize}
\item Addition property:\index{area!addition property} The total area
  of a region is the sum of the areas of the non-overlapping pieces
  which comprise the region~(see
  Figure~\ref{fig:integral:non_overlapping_regions}).

\item Inclusion property:\index{area!inclusion property} If region $B$
  is on or inside region $A$, then the area of region $B$ is less than
  or equal to the area of region $A$~(see
  Figure~\ref{fig:integral:rectangles_estimate_areas}).

\item Location-independence property:
  \index{area!location-independence property} The area of a region
  does not depend on its location~(see
  Figure~\ref{fig:integral:independence_area}).
\end{itemize}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=0.8,%
  linestyle/.style={semithick}]
% shape on left-hand side
% perimeter
\draw[linestyle] (0,0) -- (3,0);
\draw[linestyle] (0,0) -- (1,2) -- (3,2);
\draw[linestyle] (3,0) arc (-90:90:1) -- (3,2);
% dotted lines
\draw[dash pattern=on 2pt off 2pt] (1,0) -- (1,2);
\draw[dash pattern=on 2pt off 2pt] (3,0) -- (3,2);
% equal sign
\node () at (5,1) [] {\huge$=$};
% shapes on the right-hand side
% triangle
\draw[linestyle] (6,0) -- (7,2) -- (7,0) -- cycle;
% plus sign
\node () at (8,1) [] {\huge$+$};
% rectangle
\draw[linestyle] (9,0) -- (9,2) -- (11,2) -- (11,0) -- cycle;
% plus sign
\node () at (12,1) [] {\huge$+$};
% semi-circle
\draw[linestyle] (13,0) -- (13,2);
\draw[linestyle] (13,0) arc (-90:90:1) -- (13,2);
\end{tikzpicture}
\caption{Adding areas of non-overlapping regions.}
\label{fig:integral:non_overlapping_regions}
\end{figure}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangle
\filldraw[fill=gray!25,color=gray!25] (0.58,0) rectangle (2.56,2.8104);
\draw[linestyle] (0.58,0) -- (0.58,2.8104) -- (2.56,2.8104) -- (2.56,0);
% sine curve
\draw[linestyle] plot[domain=-0.4:5] (\x, {2 + 1.5*sin(\x r)});
% horizontal and vertical axes
\draw[axisstyle] (-0.2,0) -- (5.4,0);
\draw[axisstyle] (0,-0.2) -- (0,4);
\end{tikzpicture}
\caption{Estimating areas using rectangles.}
\label{fig:integral:rectangles_estimate_areas}
\index{area!estimating using rectangles}
\end{figure}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick}]
\draw[linestyle] (0,0) -- node[below]{3} (3,0) -- node[right]{2}
(3,1.5) -- (0,1.5) -- cycle;
\draw[linestyle,rotate=20] (4,0) -- node[below]{3} (7,0) -- node[right]{2}
(7,1.5) -- (4,1.5) -- cycle;
\draw[linestyle] (-1,0) -- node[below]{2} (-2.5,0) -- node[left]{3}
(-2.5,3) -- (-1,3) -- cycle;
\end{tikzpicture}
\caption{Independence of area under translation and rotation.}
\label{fig:integral:independence_area}
\end{figure}

\begin{figure}[!htbp]
\centering
\subfigure[]{
\begin{tikzpicture}
[linestyle/.style={semithick}]
\draw[linestyle] (0,0) -- node[left]{7} (0,3) -- node[above]{5} (2,3)
-- node[left]{4} (2,1.5) -- node[above]{1} (2.5,1.5) --
node[right]{3}(2.5,0) -- cycle;
\end{tikzpicture}
}
\qquad
\subfigure[]{
\begin{tikzpicture}
[linestyle/.style={semithick}]
\draw[linestyle] (0,0) -- node[left]{7} (0,3) -- node[above]{5} (2,3)
-- (2,0) -- cycle;
\draw[linestyle] (2.5,0) -- (2.5,1.5) -- node[above]{1} (3,1.5) --
node[right]{3} (3,0) -- cycle;
\end{tikzpicture}
}
\caption{Calculating areas using the addition property.}
\label{fig:integral:areas_addition_property}
\end{figure}

\begin{example}
\label{ex:integral:areas_addition_property}
Suppose the unit of measurement is inch. Determine the area of the
region in Figure~\ref{fig:integral:areas_addition_property}(a).
\end{example}

\begin{proof}[Solution]
The region can easily be broken up into two rectangles as shown in
Figure~\ref{fig:integral:areas_addition_property}(b), with areas 35
square inches and 3 square inches respectively. So the total area of
the original region is 38 square inches.
\end{proof}

Using the above three properties of area, we can get information about
areas that are difficult to calculate exactly. For instance, let $A$
be the region bounded by the graph of $f(x) = 1 / x$, the $x$-axis,
and vertical lines at $x = 1$ and $x = 3$~(refer to
Figure~\ref{fig:integral:area_under_one_over_x}). Since the two
rectangles in Figure~\ref{fig:integral:area_under_one_over_x} are
inside the region $A$ and do not overlap each other, the area of the
rectangles is $1/2 + 1/3 = 5/6$, which is less than the area of region
$A$.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=0.8,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles
\shade[top color=gray!25,bottom color=gray!25] (1.5,0) rectangle (3,0.666);
\shade[top color=gray!25,bottom color=gray!25] (3,0) rectangle (4.5,0.444);
\draw[linestyle] (1.5,0) -- (1.5,0.666) -- (3,0.666) -- (3,0);
\draw[linestyle] (3,0.444) -- (4.5,0.444) -- (4.5,0);
% function 1 / x
\draw[linestyle] plot[domain=0.7:5] function{2/x};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (5.4,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.4) node[above]{$y$};
% tick marks on the axes
\draw[linestyle] (-0.1,1.333) node[left]{1} -- (0.1,1.333);
\draw[linestyle] (1.5,-0.1) node[below]{1} -- (1.5,0.1);
\draw[linestyle] (3,-0.1) node[below]{2} -- (3,0.1);
\draw[linestyle] (4.5,-0.1) node[below]{3}-- (4.5,0.1);
% function label
\node () at (3,2) []{$f(x) = 1/x$};
\end{tikzpicture}
\caption{The area under of $y=1/x$, where $1\leq x\leq 3$.}
\label{fig:integral:area_under_one_over_x}
\end{figure}

\begin{practice}
\label{prac:integral:area_under_one_over_x}
In Figure~\ref{fig:integral:area_under_one_over_x}, let $A$ be the
region bounded by the graph of $f(x) = 1 / x$, the $x$-axis, and the
vertical lines $x = 1$ and $x = 3$. Build two rectangles, each with
base $1$ unit, outside the shaded region. Then use their areas to make
a valid statement about the area of region $A$. [Ans: Outside
rectangular area = $1.5$.]
\end{practice}

\begin{practice}
Again, let $A$ be the area of the region in
Practice~\ref{prac:integral:area_under_one_over_x}. Now use both
inside and outside rectangles with base $1/2$ unit. What can be said
about the area of region $A$ in
Figure~\ref{fig:integral:area_under_one_over_x}? [Ans: The area of the
region is between $0.95$ and $1.2$.]
\end{practice}

\begin{figure}[h]
\begin{minipage}{\textwidth}
\begin{center}
%\vspace{1.0 cm}
\includegraphics[height=5cm,width=12cm]{fig7.eps}
\end{center}
\end{minipage}
\caption{Approximating the area of a ``leaf''.}
\label{fig:7}
\end{figure}

\begin{example}
In Figure~\ref{fig:7}, there are 32 dark squares, each having a side
length of 1 centimeter, and 31 lighter squares of the
same side length. We can be sure that the area of the leaf is
smaller than what number?
\end{example}

\begin{proof}[Solution]
The area of the leaf is smaller than
$32 + 31 = 63$ cm$^2$.
\end{proof}

\begin{practice}
We can be sure that the area of the leaf is at least how large?
\end{practice}

Functions can be defined in terms of areas.\index{area!as function}
For the constant function $f(t) = 2$, define $A(x)$ to be the area of
the rectangular region bounded by the graph of $f$,
the $t$-axis, and the vertical lines at $t=1$ and $t=x$~(see
Figure~\ref{fig:integral:area_as_function}(a)). Then $A(2)$ is the
area of the shaded region in
Figure~\ref{fig:integral:area_as_function}(b), where $A(2)
=2$. Similarly, $A(3)= 4$ and $A(4)=6$. In general, we have
\[
A(x)
=
\text{base} \times \text{height}
=
(x - 1) \times 2
=
2x - 2
\]
for any $x \geq 1$. Figure~\ref{fig:integral:area_as_function}(c)
shows the graph of $y=A(x)$, whose derivative is $A'(x) = 2$ for every
value of $x \geq 1$.

\begin{figure}[!htbp]
\centering
\subfigure[]{
\begin{tikzpicture}
[scale=0.9,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangle
\shade[top color=gray!25,bottom color=gray!25] (1,0) rectangle (3,2);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (3.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,2.5) node[above]{$y$};
% tick marks on the axes
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (3,-0.1) node[below]{$x$} -- (3,0.1);
% horizontal line
\draw[linestyle] (0,2) -- (3.3,2);
% vertical lines
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,2.4);
\draw[linestyle,dash pattern=on 2pt off 2pt] (3,0) -- (3,2.4);
% labels
\node () at (3.6,1) [] {$A(x)$};
\node () at (2,2.5) [] {$f(t) = 2$};
\end{tikzpicture}
}
\quad
\subfigure[]{
\begin{tikzpicture}
[scale=0.9,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangle
\shade[top color=gray!25,bottom color=gray!25] (1,0) rectangle (2,2);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (3.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,2.5) node[above]{$y$};
% tick marks on the axes
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
% horizontal line
\draw[linestyle] (0,2) -- (3.3,2);
% vertical lines
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,2.4);
\draw[linestyle,dash pattern=on 2pt off 2pt] (2,0) -- (2,2.4);
% labels
\node () at (3,1) [] {$A(2) = 2$};
\node () at (2.9,2.5) [] {$f(t) = 2$};
\end{tikzpicture}
}
\quad
\subfigure[]{
\begin{tikzpicture}
[scale=0.9,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (3.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,4.5) node[above]{$y$};
% tick marks on the axes
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{3} -- (0.1,3);
\draw[linestyle] (-0.1,4) node[left]{4} -- (0.1,4);
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
% diagonal line
\draw[linestyle] (1,0) -- (3,4);
\node () at (3.1,1) [] {$A(x) = 2x - 2$};
\end{tikzpicture}
}
\caption{The area as a function.}
\label{fig:integral:area_as_function}
\end{figure}

Sometimes it is useful to move regions around. Consider the
parallelogram in Figure~\ref{fig:integral:area_parallelogram} and
notice the triangle on its left end. Moving this triangular region
from the left side of the parallelogram to fill the region on the
right side, we end up with a rectangle. So we have reduced the problem
of finding the area of a parallelogram to a simpler, equivalent
problem about finding the area of a rectangle.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  arrowstyle/.style={->,bend right=40,>=stealth,semithick}]
% parallelogram
\draw[linestyle] (0,0) -- (1,1) -- (4,1) -- (3,0) -- cycle;
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,1);
\node (a) at (0.5,0.2) [] {};
\node (b) at (3.7,0.2) [] {};
\path (a) edge[arrowstyle] (b);
% equal sign
\node () at (5,0.5) [] {\huge$=$};
% rectangle
\draw[linestyle] (6,0) rectangle (9,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (8,0) -- (9,1);
\end{tikzpicture}
\caption{The area of a parallelogram.}
\label{fig:integral:area_parallelogram}
\end{figure}

For complicated regions such as the shaded regions in
Figure~\ref{fig:11}(a), we can use a similar technique. At first
glance, it is difficult to estimate the total area of the shaded
regions in Figure~\ref{fig:11}(a).
However, if we slide all of them into a single column as shown in
Figure~\ref{fig:11}(b), then it is easy to determine that the shaded
area is less than the area of the enclosing rectangle: that is, area
of $\text{rectangle}
 =
\text{base} \times \text{height}
=
1 \times 2
=
2$.

\begin{figure}[h]
\begin{minipage}{\textwidth}
\begin{center}
%\vspace{1.0 cm}
\includegraphics[height=4cm,width=8cm]{fig11.eps}
\end{center}
\end{minipage}
\caption{Estimating the area of an irregular region.}
\label{fig:11}
\end{figure}


%%-----------------------------------------------------------------------%%
%%--- Applications of area ----------------------------------------------%%

\section{Applications of area}

One reason ``areas'' are so useful is that they can
represent quantities other than simple geometric
shapes. For example, if the units of the base of a rectangle are
``hours'' and the units of the height are
``miles/hour'', then the units of the ``area'' of the rectangle are
(hours) $\times$ (miles/hour) $=$ miles, a measure of distance.
Similarly, if the base units are centimeters and the height units are
grams, then the ``area'' units are gram $\times$ centimeters, a
measure of work.

\begin{example}
\label{eg:integral:distance_as_area}
In Figure~\ref{fig:integral:distance_as_area}, $f(t)$ is the velocity
of a car in miles per hour and $t$ is the time in hours. Compute the
total distance covered by the car.
\end{example}

\begin{proof}[Solution]
The shaded area is base $\times$ height $=$ 3 hours $\times$ 20
miles/hour $=$ 60 miles. In other words, the car traveled 60 miles in
the 3 hours from 1 o'clock until 4 o'clock.
\end{proof}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangle
\shade[top color=gray!25,bottom color=gray!25] (1.5,0) rectangle (6,2.5);
\draw[linestyle] (1.5,0) -- (1.5,2.5);
\draw[linestyle] (6,0) -- (6,2.5);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (6.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,3) node[above]{$v$};
% tick marks on vertical axis
\draw[linestyle] (-0.1,2.5) node[left]{20} -- (0.1,2.5);
% tick marks on horizontal axis
\draw[linestyle] (1.5,-0.1) node[below]{1 PM} -- (1.5,0.1);
\draw[linestyle] (3,-0.1) node[below]{2 PM} -- (3,0.1);
\draw[linestyle] (4.5,-0.1) node[below]{3 PM} -- (4.5,0.1);
\draw[linestyle] (6,-0.1) node[below]{4 PM} -- (6,0.1);
% horizontal line
\draw[linestyle] (0,2.5) -- (6.2,2.5);
% labels
\node () at (3.5,3) [] {$f(t) = 20 \text{ mph}$};
\node () at (6.5,1.8) [] {area};
\node () at (7.5,1.4) [] {$= \text{total distance}$};
\node () at (7.04,0.9) [] {$= 60 \text{ miles}$};
\node () at (-1.5,1.4) [rotate=90] {velocity};
\node () at (-1,1.3) [rotate=90] {(miles/hour)};
\end{tikzpicture}
\caption{Calculating distance using the area concept.}
\label{fig:integral:distance_as_area}
\end{figure}

Example~\ref{eg:integral:distance_as_area} shows that we can use the
familiar idea of area to calculate a quantity~(in this case, miles)
that at first seems totally unrelated to
area. Theorem~\ref{thm:integral:area_as_distance} provides a general
statement of the idea illustrated in
Example~\ref{eg:integral:distance_as_area}.

\begin{theorem}
\label{thm:integral:area_as_distance}
\textbf{Area as distance.}
\index{area!as distance}
Let $f(t)$ be the (positive) forward velocity of an object at time
$t$. Then the area bounded by the graph of $f$, the $t$-axis, and the
vertical lines at times $t = a$ and $t = b$, is the distance that
the object has moved forward between times $a$ and $b$.
\end{theorem}

This ``area as distance'' principle can make some difficult distance
problems much easier to handle.

\begin{example}
A car starts from rest (velocity = 0) and steadily speeds up
so that 20 seconds later its speed is 88 feet per second (60
miles per hour). How far did the car travel during those 20
seconds?
\end{example}

\begin{proof}[Solution]
If ``steadily speeds up'' means that the velocity increases linearly,
then we can apply the idea of ``area as distance''.
Figure~\ref{fig:integral:area_calculate_total_distance_of_car} shows
the graph of velocity versus time. The area of the triangular region
in the figure represents the distance traveled. Using
formula~(\ref{eq:integral:area_triangle}) for the area of a triangle,
we have
\begin{align*}
{\rm distance}
&= \frac{1}{2} \times \text{base} \times \text{height} \\
&= \frac{1}{2} \times (20 \text{ seconds}) \times (88 \text{ feet/second}) \\
&= 880 \text{ feet}.
\end{align*}
In 20 seconds the car covered a total distance of 880 feet.
\end{proof}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded triangle and diagonal line
\shade[top color=gray!25,bottom color=gray!25]
(0,0) -- (4,4.5) -- (4,0) -- cycle;
\draw[linestyle] (0,0) -- (4.3,4.84);
\draw[linestyle,dash pattern=on 2pt off 2pt] (4,0) -- (4,4.8);
\draw[linestyle,dash pattern=on 2pt off 2pt] (0,4.5) -- (4.3,4.5);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (4.6,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,5) node[above]{$v$};
% tick marks on axes
\draw[linestyle] (4,-0.1) node[below]{20} -- (4,0.1);
\draw[linestyle] (-0.1,4.5) node[left]{88} -- (0.1,4.5);
% labels on graph
\node () at (2,-0.5) [] {time (seconds)};
\node () at (-1,2) [rotate=90] {velocity};
\node () at (-0.5,2.5) [rotate=90] {(feet/second)};
\node () at (4.5,2.5) [] {area};
\node () at (5.5,2) [] {$= \text{total distance}$};
\end{tikzpicture}
\caption{Using area to calculate the distance a car travels.}
\label{fig:integral:area_calculate_total_distance_of_car}
\end{figure}

\begin{practice}
A train traveling at 45 miles per hour (66 feet/second) took 60
seconds to come to a complete stop. If the train slowed down at a
steady rate (the velocity decreases linearly), how many feet did the
train travel while coming to a stop?
\end{practice}

\begin{practice}
\label{prac:integral:walk_at_noon}
You and a friend start off at noon and walk in the same direction
along the same path at the rates shown in
Figure~\ref{fig:integral:practice_you_and_friend_walk}.
%
\begin{enumerate}
\item Who is walking faster at 2 pm? Who is ahead at 2 pm?

\item Who is walking faster at 3 pm? Who is ahead at 3 pm?

\item When will you and your friend be together? (Answer in words.)
\end{enumerate}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=1.6,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (3.7,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,2.8) node[above]{$v$};
% tick marks on the axes
\draw[linestyle] (1.105,-0.05) node[below]{1 PM} -- (1.105,0.05);
\draw[linestyle] (2.21,-0.05) node[below]{2 PM} -- (2.21,0.05);
\draw[linestyle] (3.315,-0.05) node[below]{3 PM} -- (3.315,0.05);
% vertical dash line
\draw[linestyle,dash pattern=on 2pt off 2pt] (2.21,0) -- (2.21,1.52);
% graph of functions
\draw[linestyle]
plot[domain=0:3.35] function{1.25 + 1.3*tanh(x - 2)};
\draw[linestyle]
plot[domain=0:3.35] function{1.3*log(1 + x)};
% labels
\node () at (-0.2,1.35) [rotate=90] {velocity};
\node () at (2.35,2.2) [] {friend};
\node () at (3.1,1.6) [] {you};
\end{tikzpicture}
\caption{Illustration for Practice~\ref{prac:integral:walk_at_noon}.}
\label{fig:integral:practice_you_and_friend_walk}
\end{figure}
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Total accumulation as area ----------------------------------------%%

\subsection{Total accumulation as area}

In previous examples, the function represented a rate of travel (miles
per hour) and the area represented the total distance traveled. For
functions representing other rates, the area still represents the
total amount of something. Some familiar rates include the production
of a factory (bicycles per day), the flow of water in a river (gallons
per minute), traffic over a bridge (cars per minute), or the spread of
a disease (newly sick people per week).

\begin{theorem}
\textbf{Area as total accumulation.}
\index{area!as total accumulation}
Let $f(t)$ be a positive rate~(in units per time interval) at time
$t$. Then the area between the graph of $f$, the $t$-axis, and the
vertical lines at times $t=a$ and $t=b$, is the total units which
accumulate between times $a$ and $b$.
\end{theorem}

\begin{practice}
\label{prac:integral:telephone_calls}
Figure~\ref{fig:integral:telephone_calls} shows the number of
telephone calls made per hour on a Tuesday. Approximately how many
calls were made between 9~AM and 11~AM?

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=1.6,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (3.6,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,1.8) node[above]{$v$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.05) node[below]{9 AM} -- (1,0.05);
\draw[linestyle] (2,-0.05) node[below]{10 AM} -- (2,0.05);
\draw[linestyle] (3,-0.05) node[below]{11 AM} -- (3,0.05);
% tick marks on vertical axis
\draw[linestyle] (-0.05,0.7615) node[left]{100} -- (0.05,0.7615);
\draw[linestyle] (-0.05,1.523) node[left]{200} -- (0.05,1.523);
% graphs of functions
\draw[linestyle]
plot[domain=0:2.5] function{tanh(x)};
\draw[linestyle]
plot[domain=2.5:3.3] function{sin(x-1) - 0.012};
% dash lines
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,0.7615);
\draw[linestyle,dash pattern=on 2pt off 2pt] (3,0) -- (3,0.8972);
% label
\node () at (-0.7,0.9) [rotate=90] {calls per hour};
\end{tikzpicture}
\caption{Illustration for Practice~\ref{prac:integral:telephone_calls}.}
\label{fig:integral:telephone_calls}
\end{figure}
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Problems ----------------------------------------------------------%%

\subsection{Problems}

\begin{enumerate}
\item
\begin{itemize}
\item[(a)] Calculate the sum of the rectangular areas in Figure
  \ref{fig:integral:areas_using_polygons}(a).

\item[(b)] From part~(a), what can we say about the area of the shaded
  region in Figure \ref{fig:integral:areas_using_polygons}(b)?
\end{itemize}

\item
\begin{itemize}
\item[(a)] Calculate the sum of the areas of the shaded regions in
  Figure \ref{fig:integral:areas_using_polygons}(c).

\item[(b)] From part (a), what can we say about the area of the shaded
  region in Figure \ref{fig:integral:areas_using_polygons}(b)?
\end{itemize}

\begin{figure}[!htbp]
\centering
\subfigure[\normalsize$y = 4 - 2^x$]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles
\shade[top color=gray!25,bottom color=gray!25] (0,0) rectangle (1,3);
\shade[top color=gray!25,bottom color=gray!25] (1,0) rectangle (2,2);
\draw[linestyle] (0,3) -- (1,3) -- (1,0);
\draw[linestyle] (1,2) -- (2,2) -- (2,0);
% graphs of functions
\draw[linestyle]
plot[domain=0:2] function{4 - (2**x)};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (2.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{3} -- (0.1,3);
\end{tikzpicture}
}
\quad
\subfigure[\normalsize$y = 4 - 2^x$]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% graphs of functions
\shade[linestyle,domain=0:2,top color=gray!25,bottom color=gray!25]
plot function{4 - (2**x)};
\shade[linestyle,top color=gray!25,bottom color=gray!25]
(0,0) -- (2,0) -- (0,3) -- cycle;
\draw[linestyle,domain=0:2] plot function{4 - (2**x)};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (2.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{3} -- (0.1,3);
\end{tikzpicture}
}
\quad
\subfigure[\normalsize$y = 4 - 2^x$]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded polygons
\shade[linestyle,top color=gray!25,bottom color=gray!25]
(0,0) -- (2,0) -- (1,2) -- (0,3) -- cycle;
% polygon outline
\draw[linestyle] (0,3) -- (1,2) -- (2,0);
\draw[linestyle] (1,0) -- (1,2);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (2.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{3} -- (0.1,3);
% graphs of functions
\draw[linestyle]
plot[domain=0:2] function{4 - (2**x)};
\end{tikzpicture}
}
\caption{Estimating areas using polygons.}
\label{fig:integral:areas_using_polygons}
\index{area!estimating using polygons}
\end{figure}

\item Consider the function $f(x)$ whose graph is shown in
  Figure~\ref{fig:integral:area_bounded_graph}. Let $A(x)$ represent
  the area bounded by the graph of $f(x)$, the horizontal axis, and
  vertical lines at $t = 0$ and $t = x$. Evaluate $A(x)$ for
  $x = 1, 2, 3, 4, 5$.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (5.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,2.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
\draw[linestyle] (4,-0.1) node[below]{4} -- (4,0.1);
\draw[linestyle] (5,-0.1) node[below]{5} -- (5,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
% lines and dashes
\draw[linestyle] (0,1) -- (1,1) -- (2,2) -- (3,2) -- (4,1) -- (5,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (2,0) -- (2,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (3,0) -- (3,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (4,0) -- (4,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (5,0) -- (5,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,1) -- (4,1);
% label
\node () at (4,1.7) [] {$f(x)$};
\end{tikzpicture}
\caption{Computing the area of a region bounded by a graph.}
\label{fig:integral:area_bounded_graph}
\end{figure}

\item Police chase: A speeder traveling at 45 miles per hour~(in a 25
  mph zone) passes a stopped police car, which immediately takes off
  after the speeder. The police car speeds up steadily to 60
  miles/hour in 20 seconds and then travels at a steady 60
  miles/hour. Figure~\ref{fig:integral:police_chase_problem} shows the
  velocity versus time graph for the police car and the speeder. How
  long and how far before the police car catches the speeder who
  continued traveling at 45 miles/hour?

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (5.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,6.5) node[above]{$v$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{10} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{20} -- (2,0.1);
\draw[linestyle] (5,-0.1) node[below]{?} -- (5,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{10} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{20} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{30} -- (0.1,3);
\draw[linestyle] (-0.1,4) node[left]{40} -- (0.1,4);
\draw[linestyle] (-0.1,5) node[left]{50} -- (0.1,5);
\draw[linestyle] (-0.1,6) node[left]{60} -- (0.1,6);
% lines and dash lines
\draw[linestyle] (0,0) -- (2,6) -- (5.4,6);
\draw[linestyle] (0,4.5) -- (5.4,4.5);
\draw[linestyle,dash pattern=on 2pt off 2pt] (5,0) -- (5,6);
% labels
\node () at (2.75,-1) [] {time (seconds)};
\node () at (-1,3) [rotate=90] {velocity (miles/hour)};
\end{tikzpicture}
\caption{Computing areas to analyze the police chase problem.}
\label{fig:integral:police_chase_problem}
\end{figure}

\item What are the units for the area of a rectangle with the given
  base and height units?

\begin{center}
\begin{tabular}{|l|l|l|} \hline
  Base units       & Height units     & Area units \\\hline\hline
  miles per second & seconds          &            \\
  hours            & dollars per hour &            \\
  square feet      & feet             &            \\
  kilowatts        & hours            &            \\
  houses           & people per house &            \\
  meals            & meals            &            \\\hline
\end{tabular}
\end{center}
\end{enumerate}


%%-----------------------------------------------------------------------%%
%%--- Sigma notation and Riemann sums -----------------------------------%%

\section{Sigma notation and Riemann sums}
\index{sigma notation}

So far, we have calculated the area of a region in terms of simpler
regions. We cut the region into simple shapes, calculate the area of
each simple shape, and then add these smaller areas together to get
the area of the whole region. We will continue using that approach,
but it is useful to have a notation for adding many values
together. This is where the sigma notation~(denoted with the capital
Greek letter $\Sigma$) comes in handy.

Consider the function $f(x) = 3x + 1$ and for convenience we restrict
$x$ to take only integer values. Now consider the values of $f(x)$
where $x = 2, 3, 4, 5$ as shown in
Table~\ref{tab:integral:explain_sigma_notation}. The sigma notation
allows us to express the sum $S = f(2) + f(3) + f(4) + f(5)$ using a
convenient shorthand, namely
%
\begin{equation}
\label{eq:integral:explain_sigma_notation}
S
=
\sum_{k=2}^5 3k + 1
=
f(2) + f(3) + f(4) + f(5).
\end{equation}

\begin{table}[!htpb]
\centering
\begin{tabular}{|c|c|} \hline
$x$ & $f(x) = 3x + 1$ \\\hline\hline
2   & $f(2) = 7$ \\
3   & $f(3) = 10$ \\
4   & $f(4) = 13$ \\
5   & $f(5) = 16$ \\\hline
\end{tabular}
\caption{Values of $f(x) = 3x + 1$ for $x = 2, 3, 4, 5$.}
\label{tab:integral:explain_sigma_notation}
\end{table}

Figure~\ref{fig:integral:sigma_notation} shows the various parts of
this notation. The function to the right of the sigma $\Sigma$ is
called the \emph{summand}\index{summand}. Below and above the sigma
are numbers called the \emph{lower}\index{sigma notation!lower limit}
and \emph{upper limits}\index{sigma notation!upper limit} of the
summation, respectively. Notice that instead of using the symbol $x$, in
equation~(\ref{eq:integral:explain_sigma_notation}) and
Figure~\ref{fig:integral:sigma_notation} we replaced $x$ with the
variable $k$. The variable (typically $i$, $j$, or $k$) used in the
summation is called the \emph{counter} or
\emph{index variable}.\index{sigma notation!index variable}
Table~\ref{tab:integral:reading_sigma_notation} provides various ways
of reading the $\Sigma$ notation. Using \sage, we can obtain the value
of the sum in Figure~\ref{fig:integral:sigma_notation} as follows:

\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: maxima("sum(3*k + 1, k, 2, 5)")
46
\end{lstlisting}
\end{center}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[arrowstyle/.style={semithick,->,>=stealth}]
% nodes
\node () at (0,0) [] {\Huge$\displaystyle{\sum_{k=2}^5 3k+1}$};
\node (k) at (-1.7,-1.4) [] {};
\node (var) at (-3,-2.5) [] {\text{index variable}};
\node (2) at (-0.8,-1.4) [] {};
\node (lowlimit) at (0.2,-2.5) [] {\text{lower limit}};
\node (3k1) at (0.5,-0.4) [] {};
\node (summand) at (2.2,-2) [] {\text{summand}};
\node (5) at (-1.5,1.2) [] {};
\node (upperlimit) at (-3.8,1.2) [] {\text{upper limit}};
% arrows
\path
(var) edge[arrowstyle] (k)
(lowlimit) edge[arrowstyle] (2)
(summand) edge[arrowstyle] (3k1)
(upperlimit) edge[arrowstyle] (5);
\end{tikzpicture}
\caption{The summation or sigma notation.}
\label{fig:integral:sigma_notation}
\end{figure}

\begin{table}[!htpb]
\centering
\begin{tabular}{|c|c|c|} \hline
Summation & A way to read      & Sigma \\
notation  & the sigma notation &notation \\\hline\hline
%
$1^2 + 2^2 + 3^2 + 4^2 + 5^2$ & the sum of $k$ squared & $\sum_{k=1}^5 k^2$\\
                              & for $k$ equals $1$ to $k$ equals $5$  & \\[8pt]
$\frac{1}{3} + \frac{1}{4} + \frac{1}{5} + \frac{1}{6} + \frac{1}{7}$ &
the sum of $1$ over $k$ & $\sum_{k=3}^7 k^{-1}$ \\
& for $k$ equals $3$ to $k$ equals $7$ & \\[8pt]
$2^0+2^1+2^2+2^3+2^4+2^5$ & the sum of $2$ to the $j$-th power & $\sum_{j=0}^5 2^j$ \\
& for $j$ equals $0$ to $j$ equals $5$  & \\[8pt]
$a_2+a_3+a_4+a_5+a_6+a_7$ & the sum of $a$ sub $i$ & $\sum_{i=2}^7 a_i$ \\
& for $i$ equals $2$ to $i$ equals $7$  & \\  \hline
\end{tabular}
\caption{How to read the sigma notation.}
\label{tab:integral:reading_sigma_notation}
\end{table}
\index{index variable}

\begin{practice}
Write the summation denoted by each of the following:
%
\begin{center}
(a) \quad $\sum_{k=1}^5 k^3$,\qquad
(b) \quad $\sum_{j=2}^7 (-1)^j\frac{1}{j}$,\qquad
(c) \quad $\sum_{m=0}^4 (2m+1)$.
\end{center}
\end{practice}

In practice, the sigma notation is frequently used with the standard
function notation. The following expressions are examples of using the
sigma notation with function notation:
\[
\sum_{k=1}^3 f(k+2)
=
f(1+2) + f(2+2) + f(3+2)
=
f(3) + f(4) + f(5)
\]
and
\[
\sum_{k=1}^4 f(x_i)
=
f(x_1) + f(x_2) + f(x_3) + f(x_4).
\]

\begin{table}
\centering
\begin{tabular}{|c|c|c|c|} \hline
$x$ & $f(x)$ & $g(x)$ & $h(x)$ \\\hline\hline
1   & 2      &  4     & 3 \\
2   & 3      &  1     & 3 \\
3   & 1      & $-2$   & 3 \\
4   & 0      &  3     & 3 \\
5   & 3      &  5     & 3 \\  \hline
\end{tabular}
\caption{Domain values and their images under the functions $f$, $g$,
and $h$.}
\label{tab:integral:domain_values_images}
\end{table}

\begin{example}
\label{ex:table1}
Use the values in Table~\ref{tab:integral:domain_values_images} to
evaluate (i)~$\sum_{k=2}^5 2f(k)$; and
(ii)~$\sum_{j=3}^5 \big( 5+f(j-2) \big)$.
\end{example}

\begin{proof}[Solution]
(i)
Using the values of $f(k)$ for $k = 2, 3, 4, 5$, we have
%
\begin{equation}
\label{eq:integral:sigma_function_factor}
\begin{split}
\sum_{k=2}^5 2f(k)
&= 2f(2) + 2f(3) + 2f(4) + 2f(5) \\
&= 2(3) + 2(1) + 2 (0) + 2 (3) \\
&= 14.
\end{split}
\end{equation}
%
On the other hand, note that in
expression~(\ref{eq:integral:sigma_function_factor}) we can factor out
the value $2$ to get an equivalent expression
\[
\sum_{k=2}^5 2f(k)
=
2 \sum_{k=2}^5 f(k).
\]
This expression evaluates to the same value as the original expression.

(ii)
For $j = 3, 4, 5$ we have
\[
f(3-2) = f(1),\qquad
f(4-2) = f(2),\qquad
f(5-2) = f(3).
\]
Then we get
%
\begin{equation}
\label{eq:integral:sigma_function_add}
\begin{split}
\sum_{j=3}^5 \big( 5+f(j-2) \big)
&= \big( 5+f(3-2) \big) + \big( 5+f(4-2) \big) + \big( 5+f(5-2) \big) \\
&= \big( 5+f(1) \big) + \big( 5+f(2) \big) + \big( 5+f(3) \big) \\
&= (5+2) + (5+3) + (5+1) \\
&= 21.
\end{split}
\end{equation}
%
Now carefully look at expression~(\ref{eq:integral:sigma_function_add})
again. When the index $j$ takes on each of the three values $3$, $4$,
and $5$, the term $5$ is added three times in evaluating the whole
sum. Using this observation, we can
write~(\ref{eq:integral:sigma_function_add}) in the equivalent form
\[
\sum_{j=3}^5 \big( 5 + f(j-2) \big)
=
3 \times 5 + \sum_{j=3}^5 f(j-2).
\]
This observation will be formalized later on.
\end{proof}

\begin{practice}
Use the values of $f$, $g$ and $h$ in
Table~\ref{tab:integral:domain_values_images} to evaluate the
following:
\[
(a)\quad \sum_{k=2}^5 g(k),\qquad
(b)\quad \sum_{j=1}^4 h(j),\qquad
(c)\quad \sum_{i=3}^5 \big( f(i-1)+g(i) \big).
\]
\end{practice}

Since the sigma notation is simply a notation for addition, it has all
of the familiar properties of
addition. Theorem~\ref{thm:integral:summation_properties} states a
number of these familiar addition properties for the sigma notation.

\begin{theorem}
\label{thm:integral:summation_properties}
\textbf{Summation properties.}
\index{summation properties}
Let $C$ be a fixed constant and let $m, n \in \ZZ$ be positive. Then
we have the following summation properties for the sigma notation.
%
\begin{enumerate}
\item Sum of constants: $
\sum_{k=1}^n C
=
\underbrace{C + C + C + \dots + C}_{n \text{ terms}}
=
nC$.

\item Addition:
$\sum_{k=1}^n (a_k + b_k) = \sum_{k=1}^n a_k + \sum_{k=1}^n b_k$.

\item Subtraction:
$\sum_{k=1}^n (a_k - b_k) = \sum_{k=1}^n a_k - \sum_{k=1}^n b_k$.

\item Constant multiple:
$\sum_{k=1}^n Ca_k = C \sum_{k=1}^n a_k$.

\item Preserves positivity: If $b_k \geq a_k$ for all positive
  $k \in \ZZ$, then $\sum_{k=1}^n b_k \geq \sum_{k=1}^n a_k $. In
  particular, if $a_k \geq 0$ for all positive $k \in \ZZ$ then
  $\sum_{k=1}^n a_k \geq 0$.

\item Additivity of ranges: If $1 \leq m \leq n$ then
  $\sum_{k=1}^m a_k + \sum_{k=m+1}^n a_k = \sum_{k=1}^n a_k$.
\end{enumerate}
\end{theorem}


%%-----------------------------------------------------------------------%%
%%--- Sums of areas of rectangles ---------------------------------------%%

\subsection{Sums of areas of rectangles}

Later, we will approximate the area under a curve by building
rectangles as high as the curve, calculating the area of each rectangle,
and then adding the rectangular areas together.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=2,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles
\filldraw[fill=gray!25,color=gray!25] (1,0) rectangle (1.5,0.66);
\filldraw[fill=gray!25,color=gray!25] (1.5,0) rectangle (2,0.495);
\filldraw[fill=gray!25,color=gray!25] (2,0) rectangle (2.5,0.393);
\draw[linestyle] (1,0) -- (1,0.66) -- (1.5,0.66) -- (1.5,0);
\draw[linestyle] (1.5,0.495) -- (2,0.495) -- (2,0);
\draw[linestyle] (2,0.393) -- (2.5,0.393) -- (2.5,0);
% horizontal and vertical axes
\draw[axisstyle] (-0.2,0) -- (2.8,0) node[right]{$x$};
\draw[axisstyle] (0,-0.2) -- (0,2.2) node[above]{$y$};
% tick marks on vertical axis
\draw[linestyle] (-0.05,2) node[left]{1} -- (0.05,2);
% tick marks on horizontal axis
\draw[linestyle] (0.5,-0.05) node[below]{1} -- (0.5,0.05);
\draw[linestyle] (1,-0.05) node[below]{2} -- (1,0.05);
\draw[linestyle] (1.5,-0.05) node[below]{3} -- (1.5,0.05);
\draw[linestyle] (2,-0.05) node[below]{4} -- (2,0.05);
\draw[linestyle] (2.5,-0.05) node[below]{5} -- (2.5,0.05);
% plot of y = 1/x
\draw[linestyle] plot[domain=0.48:2.7] function{1/x};
% label the graph
\node () at (1.5,1.5) [] {$y = 1 / x$};
\end{tikzpicture}
\caption{Area and summation notation with right-end rectangles.}
\label{fig:integral:area_summation_notation_right_rectangles}
\end{figure}

\begin{example}
Evaluate the sum of the rectangular areas in
Figure~\ref{fig:integral:area_summation_notation_right_rectangles} and
write the sum using sigma notation.
\end{example}

\begin{proof}[Solution]
We have
\begin{align*}
\text{sum of the rectangular areas}
&= \text{sum of (base)} \times \text{(height) for each rectangle} \\
&= (1)(1/3) + (1)(1/4) + (1)(1/5) \\
&= 47/60.
\end{align*}
Using sigma notation, we have
\[
(1)(1/3) + (1)(1/4) + (1)(1/5)
=
\sum_{k=3}^5 \frac{1}{k}
\]
which also sums to $47/60$.
\end{proof}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=2,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles
\filldraw[fill=gray!25,color=gray!25] (0.5,0) rectangle (1,2);
\filldraw[fill=gray!25,color=gray!25] (1,0) rectangle (1.5,1);
\filldraw[fill=gray!25,color=gray!25] (1.5,0) rectangle (2,0.66);
\filldraw[fill=gray!25,color=gray!25] (2,0) rectangle (2.5,0.495);
\draw[linestyle] (0.5,0) -- (0.5,2) -- (1,2) -- (1,0);
\draw[linestyle] (1,1) -- (1.5,1) -- (1.5,0);
\draw[linestyle] (1.5,0.66) -- (2,0.66) -- (2,0);
\draw[linestyle] (2,0.495) -- (2.5,0.495) -- (2.5,0);
% horizontal and vertical axes
\draw[axisstyle] (-0.2,0) -- (2.8,0) node[right]{$x$};
\draw[axisstyle] (0,-0.2) -- (0,2.2) node[above]{$y$};
% tick marks on vertical axis
\draw[linestyle] (-0.05,2) node[left]{1} -- (0.05,2);
% tick marks on horizontal axis
\draw[linestyle] (0.5,-0.05) node[below]{1} -- (0.5,0.05);
\draw[linestyle] (1,-0.05) node[below]{2} -- (1,0.05);
\draw[linestyle] (1.5,-0.05) node[below]{3} -- (1.5,0.05);
\draw[linestyle] (2,-0.05) node[below]{4} -- (2,0.05);
\draw[linestyle] (2.5,-0.05) node[below]{5} -- (2.5,0.05);
% plot of y = 1/x
\draw[linestyle] plot[domain=0.46:2.7] function{1/x};
% label the graph
\node () at (1.5,1.5) [] {$y = 1 / x$};
\end{tikzpicture}
\caption{Area and summation notation with left-end rectangles.}
\label{fig:rectangle:area_summation_left_rectangle}
\end{figure}

\begin{practice}
Evaluate the sum of the rectangular areas in
Figure~\ref{fig:rectangle:area_summation_left_rectangle} and write the
sum using sigma notation.
\end{practice}

\begin{example}
Write the sum of the areas of the rectangles in
Figure~\ref{fig:rectangle:area_general_rectangles} using sigma
notation.
\end{example}

\begin{proof}[Solution]
The area of each rectangle is base $\times$ height. The following
table shows the area of each rectangle in
Figure~\ref{fig:rectangle:area_general_rectangles}:
%
\begin{center}
\begin{tabular}{|c|c|c|c|}                                 \hline
rectangle & base        & height   & area                \\\hline\hline
1         & $x_1 - x_0$ & $f(x_1)$ & $(x_1 - x_0)f(x_1)$ \\
2         & $x_2 - x_1$ & $f(x_2)$ & $(x_2 - x_1)f(x_2)$ \\
3         & $x_3 - x_2$ & $f(x_3)$ & $(x_3 - x_2)f(x_3)$ \\
4         & $x_4 - x_3$ & $f(x_4)$ & $(x_4 - x_3)f(x_4)$ \\
5         & $x_5 - x_4$ & $f(x_5)$ & $(x_5 - x_4)f(x_5)$ \\\hline
\end{tabular}
\end{center}
%
The area of the $k$-th rectangle is $(x_k - x_{k-1}) f(x_k)$. The
total area of the rectangles is the sum
$\sum_{k=1}^5 (x_k - x_{k-1}) f(x_k)$.
\end{proof}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=3,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles
\filldraw[fill=gray!25,color=gray!25] (0.3,0) rectangle (0.9,1.245);
\filldraw[fill=gray!25,color=gray!25] (0.9,0) rectangle (1.1,1.285);
\filldraw[fill=gray!25,color=gray!25] (1.1,0) rectangle (1.8,1.305);
\filldraw[fill=gray!25,color=gray!25] (1.8,0) rectangle (2.2,1.38);
\filldraw[fill=gray!25,color=gray!25] (2.2,0) rectangle (2.4,1.48);
\draw[linestyle] (0.3,0) -- (0.3,1.245) -- (0.9,1.245) -- (0.9,0);
\draw[linestyle] (0.9,1.245) -- (0.9,1.285) -- (1.1,1.285) -- (1.1,0);
\draw[linestyle] (1.1,1.285) -- (1.1,1.305) -- (1.8,1.305) -- (1.8,0);
\draw[linestyle] (1.8,1.305) -- (1.8,1.38) -- (2.2,1.38) -- (2.2,0);
\draw[linestyle] (2.2,1.38) -- (2.2,1.48) -- (2.4,1.48) -- (2.4,0);
% horizontal and vertical axes
\draw[axisstyle] (-0.1,0) -- (2.7,0) node[right]{$x$};
\draw[axisstyle] (0,-0.1) -- (0,1.9) node[above]{$y$};
% plot of y = (1/4)(-1.5 + x)^3 + 1.3
\draw[linestyle] plot[domain=0.2:2.6] function{0.25*(-1.5 + x)**3 + 1.3};
\node () at (1.5,1.7) [] {$y = f(x)$};
% tick marks on horizontal axis
\draw[linestyle] (0.3,-0.05) node[below]{$x_0$} -- (0.3,0.05);
\draw[linestyle] (0.9,-0.05) node[below]{$x_1$} -- (0.9,0.05);
\draw[linestyle] (1.1,-0.05) node[below]{$x_2$} -- (1.1,0.05);
\draw[linestyle] (1.8,-0.05) node[below]{$x_3$} -- (1.8,0.05);
\draw[linestyle] (2.2,-0.05) node[below]{$x_4$} -- (2.2,0.05);
\draw[linestyle] (2.4,-0.05) node[below]{$x_5$} -- (2.4,0.05);
\end{tikzpicture}
\caption{Summing areas of general right-end rectangles.}
\label{fig:rectangle:area_general_rectangles}
\end{figure}


%%-----------------------------------------------------------------------%%
%%--- Area under a curve: Riemann sums ----------------------------------%%

\subsection{Area under a curve: Riemann sums}

Suppose we want to calculate the area between the graph of a positive
function $f$ and the interval $[a, b]$ on the $x$-axis~(see
Figure~\ref{fig:integral:area_between_graph_interval}(a)). The Riemann
sum method is to build several rectangles with bases on the interval
$[a, b]$ and sides that reach up to the graph of $f$~(see
Figure~\ref{fig:integral:area_between_graph_interval}(b)). Then the
areas of the rectangles can be calculated and added together to get a
number called a \emph{Riemann sum} of $f$ on $[a, b]$. The area of the
region formed by the rectangles is an approximation of the area we
want.\index{Riemann sum}

\begin{figure}[!htbp]
\centering
\subfigure[]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% graph of functions
\filldraw[fill=gray!25,color=gray!25]
(0.8,0) -- plot[domain=0.8:2.5] function{1.5 + (x - 2)**2} --
plot[domain=2.5:4] function{1.27 + sin(x - 2)} -- (4,0);
\draw[linestyle] plot[domain=0.7:2.5] function{1.5 + (x - 2)**2} --
plot[domain=2.5:4.3] function{1.27 + sin(x - 2)};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (4.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (0.8,-0.1) node[below]{$a$} -- (0.8,0.1);
\draw[linestyle] (4,-0.1) node[below]{$b$} -- (4,0.1);
% label
\node () at (2.25,2.8) [] {$y = f(x)$};
\end{tikzpicture}
}
\quad
\subfigure[]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles
\filldraw[fill=gray!25,color=gray!25] (0.8,0) rectangle (1.2571,2.5);
\filldraw[fill=gray!25,color=gray!25] (1.2571,0) rectangle (1.7142,1.7);
\filldraw[fill=gray!25,color=gray!25] (1.7142,0) rectangle (2.1714,1.7);
\filldraw[fill=gray!25,color=gray!25] (2.1714,0) rectangle (2.6285,1.5293);
\filldraw[fill=gray!25,color=gray!25] (2.6285,0) rectangle (3.0857,1.8951);
\filldraw[fill=gray!25,color=gray!25] (3.0857,0) rectangle (3.5428,2.2696);
\filldraw[fill=gray!25,color=gray!25] (3.5428,0) rectangle (4,2.4);
\draw[linestyle] (0.8,0) -- (0.8,2.5) -- (1.2571,2.5) -- (1.2571,0);
\draw[linestyle] (1.2571,1.7) -- (1.7142,1.7) -- (1.7142,0);
\draw[linestyle] (1.7142,1.7) -- (2.1714,1.7) -- (2.1714,0);
\draw[linestyle] (2.1714,1.5293) -- (2.6285,1.5293) -- (2.6285,0);
\draw[linestyle] (2.6285,1.5293) -- (2.6285,1.8951) -- (3.0857,1.8951)
-- (3.0857,0);
\draw[linestyle] (3.0857,1.8951) -- (3.0857,2.2696) -- (3.5428,2.2696)
-- (3.5428,0);
\draw[linestyle] (3.5428,2.2696) -- (3.5428,2.4) -- (4,2.4) -- (4,0);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (4.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (0.8,-0.1) node[below]{$a$} -- (0.8,0.1);
\draw[linestyle] (4,-0.1) node[below]{$b$} -- (4,0.1);
% graph of functions
\draw[linestyle] plot[domain=0.7:2.5] function{1.5 + (x - 2)**2} --
plot[domain=2.5:4.3] function{1.27 + sin(x - 2)};
% label
\node () at (2.25,2.8) [] {$y = f(x)$};
\end{tikzpicture}
}
\caption{Area between the graph of $f$ and the interval $[a, b]$.}
\label{fig:integral:area_between_graph_interval}
\end{figure}

\begin{example}
\label{ex:integral:approximate_area_by_summing_rectangles}
Approximate the area in
Figure~\ref{fig:integral:approximate_area_by_summing_rectangles}(a)
between the graph of $f$ and the interval $[2, 5]$ on the $x$-axis by
summing the areas of the rectangles in
Figure~\ref{fig:integral:approximate_area_by_summing_rectangles}(b).
\end{example}

\begin{proof}[Solution]
The total area of the rectangles is
$2 \times 3 + 1 \times 5 = 11$ square units.
\end{proof}

\begin{figure}[!htbp]
\centering
\subfigure[]{
\begin{tikzpicture}
[scale=0.8,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shading graph of function
\filldraw[fill=gray!25,color=gray!25]
(2,0) -- plot[domain=2:5] function{3.52 + 2*tanh(x - 3)} -- (5,0);
\draw[linestyle] plot[domain=1:5.5] function{3.52 + 2*tanh(x - 3)};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (6,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,6) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
\draw[linestyle] (4,-0.1) node[below]{4} -- (4,0.1);
\draw[linestyle] (5,-0.1) node[below]{5} -- (5,0.1);
% tick marks on vertical exis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{3} -- (0.1,3);
\draw[linestyle] (-0.1,4) node[left]{4} -- (0.1,4);
\draw[linestyle] (-0.1,5) node[left]{5} -- (0.1,5);
% label graph
\node () at (2.5,4) [] {$f(x)$};
\end{tikzpicture}
}
\subfigure[]{
\begin{tikzpicture}
[scale=0.8,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shading rectangles
\filldraw[fill=gray!25,color=gray!25] (2,0) rectangle (3,3);
\filldraw[fill=gray!25,color=gray!25] (3,0) rectangle (4,3);
\filldraw[fill=gray!25,color=gray!25] (4,0) rectangle (5,5);
\draw[linestyle] (2,0) -- (2,3) -- (3,3) -- (3,0);
\draw[linestyle] (3,3) -- (4,3) -- (4,0);
\draw[linestyle] (4,3) -- (4,5) -- (5,5) -- (5,0);
\draw[linestyle] plot[domain=1:5] function{3.52 + 2*tanh(x - 3)};
% horizontal dash lines
\draw[linestyle,dash pattern=on 2pt off 2pt] (0,2) -- (2,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (0,3) -- (2,3);
\draw[linestyle,dash pattern=on 2pt off 2pt] (0,5) -- (4,5);
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (5.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,6) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
\draw[linestyle] (4,-0.1) node[below]{4} -- (4,0.1);
\draw[linestyle] (5,-0.1) node[below]{5} -- (5,0.1);
% tick marks on vertical exis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
\draw[linestyle] (-0.1,3) node[left]{3} -- (0.1,3);
\draw[linestyle] (-0.1,4) node[left]{4} -- (0.1,4);
\draw[linestyle] (-0.1,5) node[left]{5} -- (0.1,5);
% label graph
\node () at (2.5,4) [] {$f(x)$};
\end{tikzpicture}
}
\caption{Approximating area by summing areas of rectangles.}
\label{fig:integral:approximate_area_by_summing_rectangles}
\end{figure}

In order to effectively describe this process, some new vocabulary is
helpful: a partition of an interval and the mesh of the partition. A
\emph{partition}\index{partition} $P$ of a closed interval $[a, b]$
into $n$ subintervals is a set of $n + 1$ points
$P = \{ x_0 = a, x_1, x_2, x_3, \dots, x_{n-1}, x_n = b \}$ in
increasing order, where $a = x_0 < x_1 < x_2 < x_3 < \cdots < x_n = b$.
\index{partition} A partition is a collection of points on an axis
and it does not depend on the function in any way.

The points of the partition $P$ divide the interval into $n$ subintervals
(see Figure~\ref{fig:integral:partition_closed_interval}):
$[x_0 , x_1]$, $[x_1 , x_2]$, $[x_2 , x_3]$, and all the way up to and
including $[x_{n-1} , x_n]$. Each partition $i$ has length
$\Delta x_i = x_i - x_{i-1}$ for $0 < i \leq n$. The points $x_i$ of
the partition $P$ are the locations of the vertical lines for the
sides of the rectangles, and the bases of the rectangles have lengths
$\Delta x_i$ for $i = 1, 2, 3, \dots, n$.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  arrowstyle/.style={->,>=stealth,semithick}]
% horizontal line
\draw[linestyle] (0,0) -- (9.5,0);
% tick marks on horizontal line
\draw[linestyle] (1,-0.1) node[below]{$a = x_0$} -- (1,0.1);
\draw[linestyle] (2.5,-0.1) node[below]{$x_1$} -- (2.5,0.1);
\draw[linestyle] (5,-0.1) node[below]{$x_2$} -- (5,0.1);
\draw[linestyle] (6,-0.1) node[below]{$x_3$} -- (6,0.1);
\draw[linestyle] (7.5,-0.1) node[below]{$x_{n-1}$} -- (7.5,0.1);
\draw[linestyle] (9,-0.1) node[below]{$b = x_n$} -- (9,0.1);
% braces
\node () at (1.75,0.3) [] {$\overbrace{\qquad\quad\;\;}$};
\node () at (3.75,0.3) [] {$\overbrace{\qquad\qquad\qquad\;}$};
\node () at (8.25,0.3) [] {$\overbrace{\quad\quad\quad\;\;\,}$};
% labels
\node (1st_subinterval) at (0.5,1.5) [] {1st subinterval};
\node (2nd_subinterval) at (4,1.5) [] {2nd subinterval};
\node (nth_subinterval) at (8,1.5) [] {$n$-th subinterval};
\node (1st_dot) at (1.75,0.4) [] {};
\node (2nd_dot) at (3.75,0.4) [] {};
\node (nth_dot) at (8.25,0.4) [] {};
\path
(1st_subinterval) edge[arrowstyle] (1st_dot)
(2nd_subinterval) edge[arrowstyle] (2nd_dot)
(nth_subinterval) edge[arrowstyle] (nth_dot);
\end{tikzpicture}
\caption{Partitioning the interval $[a,b]$.}
\label{fig:integral:partition_closed_interval}
\end{figure}

The \emph{mesh}\index{mesh} or \emph{norm}\index{norm} of the
partition is the length of the longest of the subintervals
$[x_{i-1}, x_i]$, or equivalently, the maximum of the $\Delta x_i$
for $i = 1, 2, 3, \dots , n$. For example, the set
$P = \{ 2, 3, 4.6, 5.1, 6 \}$ is a partition of the interval $[2, 6]$
that divides it into $4$ subintervals with lengths
$\Delta x_1 = 1$, $\Delta x_2 = 1.6$, $\Delta x_3 = 0.5$ and
$\Delta x_4 = 0.9$. The mesh of this partition is $1.6$, the maximum
of the lengths of the subintervals. If the mesh of a partition is
``small,'' then the length of each one of the subintervals is the same
or smaller.

A function, a partition, and a point in each subinterval determine
a Riemann sum. Suppose $f$ is a positive function on the interval
$[a, b]$, $P =\{ x_0 = a, x_1, x_2, x_3, \dots, x_{n-1}, x_n = b\}$ is
a partition of $[a, b]$, and $c_i$ is an $x$-value in the $i$-th
subinterval $[x_{i-1}, x_i]$ where $x_{i-1} \leq c_i \leq x_i$.
Then the area of the $i$-th rectangle is
$f(c_i) \cdot (x_i - x_{i-1}) = f(c_i) \Delta x_i$.
Figure~\ref{fig:integral:area_ith_rectangle} illustates the area of
the $i$-th rectangle.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick}]
% shaded rectangle and graph of function
\filldraw[fill=gray!25,color=gray!25] (0,0) rectangle (3,2);
\draw[linestyle] (0,0) -- (0,2) -- (3,2) -- (3,0);
\draw[linestyle] plot[domain=-0.5:3.5] function{1.5 + sin(x - 1.5)};
% horizontal line, vertical lines and tick marks
\draw[linestyle] (-0.5,0) -- (3.5,0);
\draw[linestyle] (0,-0.1) node[below]{$x_{i-1}$} -- (0,0.1);
\draw[linestyle] (2.0235,-0.1) node[below]{$c_i$} -- (2.0235,0.1);
\draw[linestyle] (3,-0.1) node[below]{$x_i$} -- (3,0.1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (2.0235,0) -- (2.0235,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (3,2) -- (3,2.4974);
% labels
\node () at (1.7,2.35) [] {$f(c_i)$};
\node () at (4,2.5) [] {$f(x)$};
\end{tikzpicture}
\caption{Part of a Riemann sum; the shaded rectangle has area $f(c_i)
  \cdot \Delta x_i$.}
\label{fig:integral:area_ith_rectangle}
\end{figure}

\begin{definition}
\textbf{Riemann sum.}
\index{Riemann sum}
A summation of the form $\sum_{i=1}^n f(c_i) \Delta x_i$ is called a
\emph{Riemann sum} of $f$ for the partition $P$.
\end{definition}

The Riemann sum is the total of the areas of the rectangular regions.
It is also an approximation of the area between the graph of $f$ and
the $x$-axis.

\begin{example}
Find the Riemann sum for $f(x) = 1/x$ and the partition $\{ 1, 4, 5 \}$
using the values $c_1 = 2$ and $c_2 = 5$.
\end{example}

\begin{proof}[Solution]
The two subintervals are $[1, 4]$ and $[4, 5]$ so $\Delta x_1 = 3$ and
$\Delta x_2 = 1$. Then the Riemann sum for this partition is
\[
\sum_{i=1}^n f(c_i) \Delta x_i
= f(c_1) \Delta x_1 + f(c_2) \Delta x_2
= f(2) (3) + f(5) (1)
= \frac{1}{2} (3) + \frac{1}{5} (1) = 1.7.
\]
The required Riemann sum is $1.7$.
\end{proof}

\begin{practice}
Calculate the Riemann sum for $f(x) = 1/x$ on the partition
$\{ 1, 4, 5 \}$ using the values $c_1 = 3$ and $c_2 = 4$.
\end{practice}

\begin{practice}
What is the smallest value a Riemann sum for $f(x) = 1/x$ and the
partition $\{ 1, 4, 5 \}$ can have? (Hint: You will need to select
values for $c_1$ and $c_2$.) What is the largest value a Riemann
sum can have for this function and partition?
\end{practice}

\begin{example}
Use \sage to construct the Riemann sum of the function $y = x^2$ using
a partition of $6$ equally spaced points. Take each $c_i$ to be the
midpoints.
\end{example}

\begin{proof}[Solution]
The required Riemann sum can be constructed with the following Sage
code:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: f1(x) = x^2
sage: f = Piecewise([[(-1, 1), f1]])
sage: g = f.riemann_sum(6, mode="midpoint")
sage: P = f.plot(rgbcolor=(0.7, 0.1, 0.5), plot_points=40)
sage: Q = g.plot(rgbcolor=(0.7, 0.6, 0.6), plot_points=40)
sage: L = add([line([[pf[0][0], 0], [pf[0][0], pf[1](x=pf[0][0])]],\
....: rgbcolor=(0.7, 0.6, 0.6)) for pf in g.list()])
sage: show(P + Q + L)
\end{lstlisting}
\end{center}
The plot resulting from the above code is similar to that shown in
Figure~\ref{fig:integral:Riemann_sum_parabola}.
\end{proof}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[xscale=4,%
  yscale=3.5,%
  linestyle/.style={semithick},%
  arrowstyle/.style={->,>=stealth,semithick}]
% horizontal and vertical axes
\draw[arrowstyle] (-1.2,0) -- (1.2,0) node[right]{$x$};
\draw[arrowstyle] (0,-0.1) -- (0,1.2) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (-1,-0.04) node[below]{$-1$} -- (-1,0.04);
\draw[linestyle] (1,-0.04) node[below]{1} -- (1,0.04);
% tick marks on vertical axis
\draw[linestyle] (-0.04,1)  node[left]{1} -- (0.04,1);
% graph of function
\draw[linestyle] plot[domain=-1:1] function{x**2};
% rectangles under graph of function
\draw[linestyle] (-1,0) -- (-1,0.6944) -- (-0.6666,0.6944) -- (-0.6666,0);
\draw[linestyle] (-0.6666,0.25) -- (-0.3333,0.25) -- (-0.3333,0);
\draw[linestyle] (-0.3333,0.0277) -- (0.3333,0.0277);
\draw[linestyle] (0.3333,0) -- (0.3333,0.25) -- (0.6666,0.25);
\draw[linestyle] (0.6666,0) -- (0.6666,0.6944) -- (1,0.6944) -- (1,0);
\end{tikzpicture}
\caption{Riemann sum for the parabola $y = x^2$.}
\label{fig:integral:Riemann_sum_parabola}
\end{figure}

At the end of this section is a Python\footnote{
Python is a general purpose cross-platform, free and open source
computer programming language. It is widely used in industry and
academia, and is available for download at
\url{http://www.python.org}. Alternatively, you can download the
mathematical software system \sage from \url{http://www.sagemath.org}.
It comes with Python pre-installed.
}\index{Python} program listing for calculating Riemann sums of
$f(x) = 1/x$ on the interval $[1, 5]$ using $100$ subintervals. It can
be modified easily to work for different functions, different
endpoints, and different numbers of
subintervals. Table~\ref{tab:integral:Python_Riemann_sums} shows the
results of running the program with different numbers of subintervals
and different ways of selecting the points $c_i$ in each
subinterval. When the mesh of the partition is small and the number of
subintervals large, all of the ways of selecting the $c_i$ lead to
approximately the same number for the Riemann sums.

Here is a Python program to calculate Riemann sums of $f(x) = 1/x$ on
$[1, 5]$ using $100$ equal length subintervals, based on the left-hand
endpoints.
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
f = lambda x: 1/x                              # define the function
a = 1.0                                        # left endpoint of integral
b = 5.0                                        # right endpoint of integral
n = 100                                        # number of subintervals
Dx = (b - a)/n                                 # width of each subinterval
rsum = sum([f(a + i*Dx)*Dx for i in range(n)]) # compute the Riemann sum
print rsum                                     # print the Riemann sum
\end{lstlisting}
\end{center}
%
Other Riemann sums can be calculated by replacing the \texttt{rsum}
line with one of:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
rsum = sum([f(a + (i + 0.5)*Dx)*Dx for i in range(n)])  # mid-point
\end{lstlisting}
\end{center}
%
or
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
rsum = sum([f(a + (i + 1)*Dx)*Dx for i in range(n)])  # right-hand
\end{lstlisting}
\end{center}
%
Written as Python ``functions,'' these three are written as
below\footnote{
If you have an electronic copy of this file and ``copy-and-paste''
these into Python, keep in mind that indenting is very important in
Python syntax. The following style guide explains why indenting is
important in Python:
\url{http://www.python.org/doc/essays/styleguide.html}.
}
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
def rsum_lh(n):
    f = lambda x: 1/x
    a = 1.0
    b = 5.0
    Dx = (b - a)/n
    return sum([f(a + i*Dx)*Dx for i in range(n)])

def rsum_mid(n):
    f = lambda x: 1/x
    a = 1.0
    b = 5.0
    Dx = (b - a)/n
    return sum([f(a + (i + 0.5)*Dx)*Dx for i in range(n)])

def rsum_rh(n):
    f = lambda x: 1/x
    a = 1.0
    b = 5.0
    Dx = (b - a)/n
    return sum([f(a + (i + 1)*Dx)*Dx for i in range(n)])
\end{lstlisting}
\end{center}
%
The commands
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sizes = [5, 10, 20, 100, 1000]
table = [[n, (b - a)/n, rsum_lh(n), rsum_mid(n), rsum_rh(n)] for n in sizes]
\end{lstlisting}
\end{center}
%
yield the data shown in
Table~\ref{tab:integral:Python_Riemann_sums}. In fact, the exact value
is $\log(5) = 1.609437\dots$, so the last few lines of
Table~\ref{tab:integral:Python_Riemann_sums} yield pretty good
approximations.

\begin{table}
\centering
\begin{tabular}{|l|l|c|c|c|} \hline
     &              & left-hand          & mid-point          & right-hand         \\
$n$  & $\Delta x_i$ & Riemann sum        & Riemann sum        & Riemann sum        \\\hline\hline
5    & 0.8          & 1.9779070602600015 & 1.5861709609993364 & 1.3379070602600014 \\
10   & 0.4          & 1.7820390106296689 & 1.6032106782106783 & 1.4620390106296690 \\
20   & 0.2          & 1.6926248444201737 & 1.6078493243021688 & 1.5326248444201738 \\
100  & 0.04         & 1.6255658911511259 & 1.6093739310551827 & 1.5935658911511259 \\
1000 & 0.004        & 1.6110391924319691 & 1.6094372724359669 & 1.6078391924319690 \\\hline
\end{tabular}
\caption{Computing Riemann sums using Python.}
\label{tab:integral:Python_Riemann_sums}
\end{table}

\begin{practice}
Replace $1/x$ with $x^2$ and $[a, b] = [1,5]$ with $[a,b]=[-1,1]$ in
the Python code above. Compute the Riemann sum for the new function
with $n = 100$. Use the mid-point approximation. (You may use \sage or
Python, whichever you prefer.)
\end{practice}

\begin{example}
\label{ex:integral:Riemann_sum_sin_x}
Compute the Riemann sum for the function $f(x) = \sin(x)$ on the
interval $[0, \pi]$. Use the partition $P = \{ 0, \pi/4, \pi/2, \pi \}$
with $c_1 = \pi/4$, $c_2 = \pi/2$, and $c_3 = 3\pi/4$.
\end{example}

\begin{proof}[Solution]
The $3$ subintervals are $[0, \pi/4]$, $[\pi/4, \pi/2]$, and
$[\pi/2, \pi]$. The corresponding subinterval lengths are
$\Delta x_1 = \pi/4$, $\Delta x_2 = \pi/4$, and $\Delta x_3 = \pi/2$.
The Riemann sum for the partition $P$ is
%
\begin{align*}
\sum_{i=1}^3 f(c_i) \Delta x_i
&= \sin(\pi/4) (\pi/4) + \sin(\pi/2) (\pi/4) + \sin(3\pi/4) (\pi/2) \\
&= \frac{1}{\sqrt{2}} \frac{\pi}{4} + 1 \cdot \frac{\pi}{4} +
   \frac{1}{\sqrt{2}} \frac{\pi}{2}
\end{align*}
which sums to $2.45148\dots$.
\end{proof}

\begin{practice}
Compute the Riemann sum for the function and partition in
Example~\ref{ex:integral:Riemann_sum_sin_x}, but use $c_1 = 0$,
$c_2 = \pi/2$, and $c_3 = \pi/2$.
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Summing powers of consecutive integers ----------------------------%%

\subsubsection*{Summing powers of consecutive integers}
\index{summing integer powers}

Explicit formulas for some commonly encountered summations are known
and are useful for explicitly evaluating some Riemann sums and their
limits. The formulas below are included here for your reference. They
are not necessary for the remainder of this chapter.

The summation formula for the first $n$ positive integers is relatively
well-known, has several easy but clever proofs, and even has an
interesting story. The sum of all integers from 1 up to and including
an integer $n > 1$ is given by the formula
\[
1 + 2 + 3 + \cdots + (n - 1) + n
=
\sum_{i=1}^n i
=
\frac{n (n + 1)}{2}.
\]
To see why this formula is true, consider the sum
$S = 1 + 2 + 3 + \cdots + (n - 1) + n$. Rearranging the summands, we
also have $S = n + (n - 1) + (n - 2) + \cdots + 3 + 2 + 1$. Add these
two representations of $S$ together to produce
%
\begin{align*}
2S
&= (1 + n) + (2 + (n - 1)) + (3 + (n - 2)) + \cdots +
   ((n - 2) + 3) + ((n - 1) + 2) + (n + 1) \\
&= \underbrace{(n + 1) + (n + 1) + \cdots + (n + 1)}_{\text{$n$ copies
of $(n + 1)$}} \\
&= n (n + 1).
\end{align*}
%
Then $S = n(n + 1) / 2$ as required.

It is said that Gauss\index{Gauss, Carl Friedrich} discovered this
formula for himself at the age of 5. His teacher, planning on keeping
the class busy for a while, asked the students to add the integers
from 1 to 100. Gauss thought a few minutes, wrote his answer on his
slate, and turned it in. According to the story, he then sat smugly
while his classmates struggled with the problem.

Below are some formulas for integer powers of the first $n$
integers:\index{summing integer powers}
%
\begin{align*}
\sum_{i=1}^n i
&= \frac{1}{2} n^2 + \frac{1}{2} n = \frac{n(n + 1)}{2} \\
\sum_{i=1}^n i^2
&= \frac{1}{3} n^3 + \frac{1}{2} n^2 + \frac{3}{12} n
= \frac{n(n + 1)(2n + 1)}{6} \\
\sum_{i=1}^n i^3
&= \frac{1}{4} n^4 + \frac{1}{2} n^3 + \frac{3}{12} n^2
= \left( \frac{n(n + 1)}{2} \right)^2 \\
\sum_{i=1}^n i^4
&= \frac{1}{5} n^5 + \frac{1}{2} n^4 + \frac{4}{12} n^3 - \frac{1}{30} n
= \frac{n(n + 1) (2n + 1) (3n^2 + 3n - 1)}{30}
\end{align*}

\begin{practice}
Use the properties of summation and the formulas for powers to
evaluate each of the following sums:
%
\begin{center}
(a) \quad $\sum_{k=1}^{10} (3 + 2k + k^2)$ \qquad
(b) \quad $\sum_{k=1}^{10} k (k^2 + 1)$ \qquad
(c) \quad $\sum_{k=1}^{10} k^2 (k - 3)$
\end{center}
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Lower and upper Riemann sums --------------------------------------%%

\subsection{Lower and upper Riemann sums}

Two particular Riemann sums are of special interest because they
represent the extreme possibilities for Riemann sums for a given
partition.

\begin{definition}
\textbf{Lower and upper Riemann sums.}
\index{Riemann sum!lower}
\index{Riemann sum!upper}
Suppose $f$ is a positive function on $[a, b]$ and $P$ is a partition
of $[a, b]$. Let $m_i$ be the $x$-value in the $i$-th subinterval such
that $f(m_i)$ is the minimum value of $f$ in that interval. Also let
$M_i$ be the $x$-value in the $i$-th subinterval such that $f(M_i)$ is
the maximum value of $f$ in that interval. Then the
\emph{lower Riemann sum} is defined as
\[
S_L = \sum_{i=1}^n f(m_i) \Delta x_i
\]
and the \emph{upper Riemann sum} is given by
\[
S_U = \sum_{i=1}^n f(M_i) \Delta x_i.
\]
\end{definition}

Geometrically, the lower sum comes from building rectangles under the
graph of $f$~(see
Figure~\ref{fig:integral:lower_upper_Riemann_sums}(a)). The lower
sum is less than or equal to the exact area $A$, i.e. $S_L \leq A$ for
every partition $P$. The upper sum comes from building rectangles over
the graph of $f$~(see
Figure~\ref{fig:integral:lower_upper_Riemann_sums}(b)). The upper sum
is greater than or equal to the exact area $A$, i.e. $S_U \geq A$ for
every partition $P$. The lower and upper sums provide bounds on the
size of the exact area, i.e. the exact area is bounded by the
inequality $S_L \leq A \leq S_U$.

\begin{figure}[!htbp]
\centering
\subfigure[Lower sum.]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  arrowstyle/.style={->,>=stealth,semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles and graph of function
\filldraw[fill=gray!25,color=gray!25] (1,0) rectangle (2.5,1.335);
\filldraw[fill=gray!25,color=gray!25] (2.5,0) rectangle (3,1.635);
\filldraw[fill=gray!25,color=gray!25] (3,0) rectangle (5.5,1.22);
\filldraw[fill=gray!25,color=gray!25] (5.5,0) rectangle (6,2.04);
\draw[linestyle] (1,0) -- (1,1.335) -- (2.5,1.335) -- (2.5,0);
\draw[linestyle] (2.5,1.3414) -- (2.5,1.635) -- (3,1.635) -- (3,0);
\draw[linestyle] (3,1.22) -- (5.5,1.22) -- (5.5,0);
\draw[linestyle] (5.5,1.22) -- (5.5,2.04) -- (6,2.04) -- (6,0);
\draw[linestyle] plot[domain=0.5:6.4] function{0.5*x + sin(x)};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (6.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% labels
\node () at (1.75,2.5) [] {$f(x)$};
\end{tikzpicture}
}
\quad
\subfigure[Upper sum.]{
\begin{tikzpicture}
[linestyle/.style={semithick},%
  arrowstyle/.style={->,>=stealth,semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangles and graph of function
\filldraw[fill=gray!25,color=gray!25] (1,0) rectangle (2.5,1.915);
\filldraw[fill=gray!25,color=gray!25] (2.5,0) rectangle (3,1.8484);
\filldraw[fill=gray!25,color=gray!25] (3,0) rectangle (5.5,2.0444);
\filldraw[fill=gray!25,color=gray!25] (5.5,0) rectangle (6,2.7205);
\draw[linestyle] (1,0) -- (1,1.915) -- (2.5,1.915) -- (2.5,0);
\draw[linestyle] (2.5,1.8484) -- (3,1.8484) -- (3,0);
\draw[linestyle] (3,1.8484) -- (3,2.0444) -- (5.5,2.0444) -- (5.5,0);
\draw[linestyle] (5.5,2.0444) -- (5.5,2.7205) -- (6,2.7205) -- (6,0);
\draw[linestyle] plot[domain=0.5:6.4] function{0.5*x + sin(x)};
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (6.5,0) node[right]{$x$};
\draw[axisstyle] (0,-0.25) -- (0,3.5) node[above]{$y$};
% labels
\node () at (1.75,2.5) [] {$f(x)$};
\end{tikzpicture}
}
\caption{Lower and upper Riemann sums.}
\label{fig:integral:lower_upper_Riemann_sums}
\end{figure}

Unfortunately, finding minima and maxima can be a time-consuming
process. It is usually not practical to determine lower and upper sums
for arbitrary functions. However, if $f$ is monotonic, then it is easy
to find the values for $m_i$ and $M_i$ , and sometimes we can
explicitly calculate the limits of the lower and upper sums. For a
monotonic bounded function, we can guarantee that a Riemann sum is
within a certain distance of the exact value of the area it is
approximating.

\begin{theorem}
Let $f$ be a positive, monotonically increasing, bounded function on
$[a,b]$. Denote by $\delta_{SA}$ the distance between the Riemann sum
and the exact area. Also, let $\delta_{UL}$ be the distance between
the upper sum and the lower sum and let $\mesh(P)$ be the mesh
of a partition $P$. Then for any partition $P$ and any Riemann sum for
$P$, we have
\[
\delta_{SA}
\leq
\delta_{UL}
\leq \big( f(b) - f(a) \big) \cdot \mesh(P).
\]
\end{theorem}

\begin{proof}
The Riemann sum and the exact area are both between the upper and
lower sums. Then $\delta_{SA}$ is less than or equal to
$\delta_{UL}$. Since $f$ is monotonically increasing, the areas
representing the difference of the upper and lower sums can be slid
into a rectangle whose height equals $f(b) - f(a)$ and whose base
equals $\mesh(P)$. Then the total difference of the upper and
lower sums is less than or equal to the area of the rectangle, i.e.
$\big( f(b) - f(a) \big) \cdot \mesh(P)$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Problems ----------------------------------------------------------%%

\subsection{Problems}

For the first four problems, sketch the function. Then compute the
smallest possible value and the largest possible value for a Riemann
sum of the given function and partition.

\begin{enumerate}
\item $f(x) = 1 + x^2$
  \begin{itemize}
  \item[(a)] $P = \{ 1, 2, 4, 5 \}$

  \item[(b)] $P = \{ 1, 2, 3, 4, 5 \}$

  \item[(c)] $P = \{ 1, 1.5, 2, 3, 4, 5 \}$
  \end{itemize}

\item $f(x) = 7 - 2x$
  \begin{itemize}
  \item[(a)] $P = \{ 0, 2, 3 \}$

  \item[(b)] $P = \{ 0, 1, 2, 3 \}$

  \item[(c)] $P = \{ 0, .5, 1, 1.5, 2, 3 \}$
  \end{itemize}

\item $f(x) = \sin(x)$
  \begin{itemize}
  \item[(a)] $P = \{ 0, \pi/2, \pi \}$

  \item[(b)] $P = \{ 0, \pi/4, \pi/2, \pi \}$

  \item[(c)] $P = \{ 0, \pi/4, 3\pi/4, \pi \}$
  \end{itemize}

\item $f(x) = x^2 - 2x + 3$
  \begin{itemize}
  \item[(a)] $P = \{ 0, 2, 3 \}$

  \item[(b)] $P = \{ 0, 1, 2, 3 \}$

  \item[(c)] $P = \{ 0, .5, 1, 2, 2.5, 3 \}$.
  \end{itemize}

\item Suppose we divide the interval $[1, 4]$ into $100$ equally wide
  subintervals and calculate a Riemann sum for $f(x) = 1 + x^2$ by
  randomly selecting a point $c_i$ in each subinterval.
  \begin{itemize}
  \item[(a)] We can be certain that the value of the Riemann sum is
    within what distance of the exact value of the area between the
    graph of $f$ and the interval $[1, 4]$?

  \item[(b)] What if we take $200$ equally long subintervals?
  \end{itemize}

\item Let $f$ be monotonic decreasing on $[a, b]$. Now divide the
  interval $[a, b]$ into $n$ equally wide subintervals. We can be
  certain that the Riemann sum is within what distance of the exact
  value of the area between $f$ and the interval $[a, b]$?

\item Suppose $S_L = 7.362$ and $S_U = 7.402$ for a positive function
  $f$ and a partition $P$ of the interval $[1, 5]$.
  \begin{itemize}
  \item[(a)] We can be certain that every Riemann sum for the
    partition $P$ is within what distance of the exact value of the
    area under the graph of $f$ over the interval $[1, 5]$?

  \item[(b)] What if $S_L = 7.372$ and $S_U = 7.390$?
  \end{itemize}
\end{enumerate}


%%-----------------------------------------------------------------------%%
%%--- The definite integral ---------------------------------------------%%

\section{The definite integral}

Each particular Riemann sum depends on several things: the function
$f$, the interval $[a, b]$, the partition $P$ of the interval, and the
values chosen for $c_i$ in each subinterval. Fortunately, for most of
the functions needed for applications, as the approximating rectangles
get thinner (as the mesh of $P$ approaches $0$ and the number of
subintervals gets bigger) the values of the Riemann sums approach the
same value independently of the particular partition $P$ and the
points $c_i$. For these functions, the \emph{limit}~(as the mesh
approaches $0$) of the Riemann sums is the same number no matter how
the $c_i$'s are chosen. This limit of the Riemann sums is the next big
topic in calculus: the definite integral. Integrals arise throughout
the rest of this book and in applications in almost every field that
uses mathematics.

\begin{definition}
\label{def:integral:integral}
\textbf{Definite integral.}
\index{definite integral}
\index{Riemann integrable}
If $\lim_{\mesh(P) \rightarrow 0} \sum_{i=1}^n f(c_i) \Delta x_i$
equals a finite number $I$, then $f$ is said to be
\emph{(Riemann) integrable} on the interval $[a, b]$. The number $I$
is called the \emph{definite integral} of $f$ over $[a, b]$ and is
written as
\[
\lim_{\mesh(P) \rightarrow 0} \sum_{i=1}^n f(c_i) \Delta x_i
=
I
=
\int_a^b f(x) \, dx.
\]
\end{definition}

The symbol $\int_a^b f(x) \, dx$ is read as ``the integral from $a$ to
$b$ of $f$ of $x$ dee $x$'' or ``the integral from $a$ to $b$ of
$f(x)$ with respect to $x$.'' The
\emph{lower limit}\index{integral!lower limit} is $a$, the
\emph{upper limit}\index{integral!upper limit} is $b$, the
\emph{integrand}\index{integrand} is $f(x)$, and $x$ is
sometimes called the \emph{dummy variable}.\index{dummy variable} Note
that $\int_a^b f(u) \, du$ numerically means exactly the same thing, but
with a different dummy variable.

The value of a definite integral $\int_a^b f(x) \, dx$ depends only on
the function $f$ being integrated and on the end points $a$ and
$b$. Each of the following integrals represents the integral of the
function $f$ on the interval $[a,b]$ and they are all equal:
\[
\int_a^b f(x) \, dx
=
\int_a^b f(t) \, dt
=
\int_a^b f(u) \, du
=
\int_a^b f(z) \, dz.
\]
Also, note that when the upper and the lower limits are the same then
the integral is always $0$:
\[
\int_{a}^a f(x) \, dx = 0.
\]
There are many other properties, as we will see later.

%% starting to take from Stein now

\begin{table}[!htbp]
\centering
\begin{tabular}{|l|l|l|l|l|l|l|l|}                \hline
Time (seconds) & 0 & 1 & 2  & 3  & 4  & 5  & 6  \\\hline
Speed (mph)    & 0 & 5 & 15 & 25 & 40 & 50 & 60 \\\hline
\end{tabular}
\caption{Speed versus time readings for a sports car.}
\label{tab:integral:speed_readings_sports_car}
\end{table}

\begin{example}
(Relation between velocity and area.) Suppose you are reading a car
magazine and there is an article about a new sports car that contains
Table~\ref{tab:integral:speed_readings_sports_car}. The article claims
that the car drove $1/8$th of a mile after $6$ seconds, but this just
``feels'' wrong. Estimate the distance driven using the formula
%
\begin{equation}
\label{eq:integral:estimate_distance_travelled}
\text{distance} = \text{rate} \times \text{time}.
\end{equation}
\end{example}

\begin{proof}[Solution]
We overestimate by assuming the velocity is a constant equal to the
maximum on each interval:
\[
\text{estimate}
=
5 \cdot 1 + 15 \cdot 1 + 25 \cdot 1 + 40 \cdot 1 + 50 \cdot 1 + 60 \cdot 1
=
\frac{195}{3600} \text{miles}
=
0.054\dots
\]
(Note: there are $3600$ seconds in an hour.) But $1/8 \approx 0.125$, so
the article is inconsistent.  (Doesn't this sort of thing just bug
you?  By learning calculus you will be able to double-check things
like this much more easily.)
\end{proof}

Formula~(\ref{eq:integral:estimate_distance_travelled}) for estimating
the distance traveled looks exactly like an approximation for the area
under the graph of the speed of the car. In fact, if an object has
velocity $v(t)$ at time $t$, then the net change in position from time
$a$ to $b$ is
\[
\int_a^b v(t) \, dt.
\]

If $f$ represents velocity, then the integrals on the intervals where
$f$ is positive measure the distances moved forward. The integrals on
the intervals where $f$ is negative measure the distances moved
backward. Finally, the integral over the whole time interval is the
total (or net) change in position, i.e. the distance moved forward
minus the distance moved backward.

\begin{practice}
A bug starts at the location $x = 12$ on the $x$-axis at 1~PM. It
walks along the axis in the positive direction with the velocity shown
in Figure~\ref{fig:integral:velocity_of_bug}. How far does the bug
travel between 1~PM and 3~PM. Where is the bug at 3~PM?
\end{practice}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.2,0) -- (5,0) node[right]{$t$};
\draw[axisstyle] (0,-1.5) -- (0,1.5) node[above]{$v$};
% tick marks on horizontal axis
\draw[linestyle] (1.5,-0.1) node[below]{1 PM} -- (1.5,0.1);
\draw[linestyle] (3,-0.1) node[below]{2 PM} -- (3,0.1);
\draw[linestyle] (4.5,-0.1) -- node[above]{3 PM} (4.5,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{10} -- (0.1,1);
\draw[linestyle] (-0.1,-1) node[left]{-10} -- (0.1,-1);
% lines and dash lines
\draw[linestyle] (1.5,1) -- (3,1) -- (4.5,-1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (1.5,0) -- (1.5,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (3,0) -- (3,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (4.5,0) -- (4.5,-1);
% labels
\node () at (-1.4,0) [rotate=90] {velocity};
\node () at (-0.9,0) [rotate=90] {(feet/hour)};
\end{tikzpicture}
\caption{Velocity of a bug on the $x$-axis.}
\label{fig:integral:velocity_of_bug}
\end{figure}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.2,0) -- (6.5,0) node[right]{$t$};
\draw[axisstyle] (0,-2.5) -- (0,2.5) node[above]{$v$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1 PM} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
\draw[linestyle] (4,-0.1) node[below]{4} -- (4,0.1);
\draw[linestyle] (5,-0.1) node[below]{5} -- (5,0.1);
\draw[linestyle] (6,-0.1) -- node[above]{6 PM} (6,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,-2) node[left]{-20} -- (0.1,-2);
\draw[linestyle] (-0.1,-1) node[left]{-10} -- (0.1,-1);
\draw[linestyle] (-0.1,1) node[left]{10} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{20} -- (0.1,2);
% lines and dash lines
\draw[linestyle] (0,2) -- (4,-2) -- (6,-2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (6,-2) -- (6,0);
% labels
\node () at (-1,0) [rotate=90] {velocity~(miles/hour)};
\end{tikzpicture}
\caption{Velocity of a car on the $x$-axis.}
\label{fig:integral:velocity_car_x_axis}
\end{figure}

\begin{practice}
A car is driven west with the velocity shown in
Figure~\ref{fig:integral:velocity_car_x_axis}.
\begin{itemize}
\item[(a)] Between noon and 6~PM, how far does the car travel?

\item[(b)] At 6~PM, where is the car relative to its starting point
  (its position at noon)?
\end{itemize}
\end{practice}


\subsubsection*{Units for the definite integral}

We have already seen that the area under a graph can represent
quantities whose units are not the usual geometric units of square
meters or square feet. In general, the units for the definite integral
$\int_a^b f(x) \, dx$ are
\[
\text{units for } f(x) \times \text{units for }x.
\]
A quick check of the units can help avoid errors in setting up an
applied problem.

For example, if $x$ is a measure of time in seconds and $f(x)$ is a
velocity with units feet/second, then $\Delta x$ has the units seconds
and $f(x) \Delta x$ has the units
\[
\frac{\text{feet}}{\text{second}} \times \text{seconds}
=
\text{feet}
\]
which is a measure of distance. Since each Riemann sum
$\sum f(x_i) \Delta x_i$ is a sum of feet and the definite integral is
the limit of the Riemann sums, the definite integral
$\int_a^b f(x) \, dx$ has the same units, i.e. feet. However, if
$f(x)$ is a force in grams and $x$ is a distance in centimeters, then
$\int_a^b f(x) \, dx$ is a number with the units
\[
\text{gram} \times \text{centimeters}
\]
which is a measure of work.


%%-----------------------------------------------------------------------%%
%%--- The Fundamental Theorem of Calculus -------------------------------%%

\subsection{The Fundamental Theorem of Calculus}

\begin{example}
\label{ex:integral:area_Ax_function_ft}
For the function $f(t) = 2$, define $A(x)$ to be the area of the
region bounded by the graph of $f$, the $t$-axis, and vertical lines
at $t = 1$ and $t = x$.
%
\begin{itemize}
\item[(a)] Evaluate $A(1)$, $A(2)$, $A(3)$, and $A(4)$.

\item[(b)] Find an algebraic formula for $A(x)$ with $x \geq 1$.

\item[(c)] Calculate $\frac{d}{dx} A(x)$.

\item[(d)] Describe $A(x)$ as a definite integral.
\end{itemize}
\end{example}

\begin{proof}[Solution]
(a) $A(1) = 0$, $A(2) = 2$, $A(3) = 4$, and $A(4) = 6$.

(b) $A(x)$ is the area of a rectangle. So the area is base $\times$
  height, which equals $(x - 1) \times 2 = 2x - 2$.

(c) $\frac{d}{dx} A(x) = \frac{d}{dx} (2x - 2) = 2$.

(d) $A(x) = \int_1^x 2 \, dt$.
\end{proof}

\begin{practice}
\label{prac:integral:area_Ax_function_ft}
Answer the questions in Example~\ref{ex:integral:area_Ax_function_ft}
for $f(t) = 3$.
\end{practice}

A curious coincidence appeared in
Example~\ref{ex:integral:area_Ax_function_ft} and
Practice~\ref{prac:integral:area_Ax_function_ft}. The derivative of
the function defined by the integral was the same as the integrand,
i.e. the function inside the integral. Stated another way, the
function defined by the integral was an
\emph{antiderivative}\index{antiderivative} of the function inside the
integral. We will see that this is no coincidence: it is an important
property called The Fundamental Theorem of Calculus.

\begin{theorem}
\label{thm:integral:fundamental_theorem_calculus}
\textbf{Fundamental Theorem of Calculus.}
\index{Fundamental Theorem of Calculus}
Let $f$ be a continuous function on the interval $[a, b]$. If $F(x)$
is a differentiable function on $[a, b]$ such that $F'(x) = f(x)$,
then
\[
\int_a^b f(x) \, dx = F(b) - F(a).
\]
\end{theorem}

The above theorem is \emph{incredibly} useful in mathematics, physics,
biology, and many other areas. One reason it is amazing is because it
says that the area under the entire curve is completely determined by
the values of an auxiliary function \emph{at only two points}. This is
hard to believe!
Theorem~\ref{thm:integral:fundamental_theorem_calculus} reduces
computing~(\ref{def:integral:integral}) to finding a single function
$F$, which one can often do algebraically in practice. Whether or not
one should use Theorem~\ref{thm:integral:fundamental_theorem_calculus}
to evaluate an integral depends a lot on the application at hand. One
can also use a partial limit via a computer for certain applications,
e.g. numerical integration.

\begin{example}
What is the area under a ``hump'' of the graph of $\sin$? Use the
function $F(x) = -\cos(x)$.
\end{example}

\begin{proof}[Solution]
With $F(x) = -\cos(x)$, we apply
Theorem~\ref{thm:integral:fundamental_theorem_calculus} to obtain
\[
\int_0^\pi \sin(x) \, dx
=
-\cos(\pi) - (-\cos(0))
=
-(-1) - (-1)
=
2.
\]
In \sage, we can do this both algebraically and numerically as
follows.
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: f = lambda x: sin(x)
sage: integral(f(x), x, 0, pi)
2
sage: numerical_integral(f(x), 0, pi)
(1.9999999999999998, 2.2204460492503128e-14)
\end{lstlisting}
\end{center}
%
For the algebraic computation, \sage knows how to integrate $\sin(x)$
exactly, so it can compute $\int_0^\pi \sin(x) \, dx = 2$ using its
\verb!integral! command.\footnote{
\sage includes Maxima~(\url{http://maxima.sourceforge.net})
and calls Maxima to compute this integral.
}
On the last line of output, the first entry is the approximation
and the second is the error bound.

For the numerical computation, \sage obtains\footnote{
\sage includes the GNU Scientific
Library~(\url{http://www.gnu.org/software/gsl/}) and calls it to
approximate this integral.
}
the approximation $\int_0^\pi \sin(x) \, dx \approx 1.99999\dots$ by
taking enough terms in a Riemann sum to achieve a very small error.
(A lot of theory of numerical integration goes into why
\verb!numerical_integral! works correctly, but that would take us too
far afield to explain here.)
\end{proof}

\begin{example}
Let $\lfloor x \rfloor$\index{floor function} denote the greatest
integer (or floor) function, so
$\lfloor 1/2 \rfloor = \lfloor 0.5 \rfloor = 0$ and
$\lfloor 3/2 \rfloor = \lfloor 1.5 \rfloor = 1$. Evaluate
$\int_{1/2}^{3/2} \lfloor x \rfloor \, dx$. The function
$y=\lfloor x \rfloor$ is sometimes called the
``staircase function''\index{staircase function}
because of the look of its discontinuous graph as shown in
Figure~\ref{fig:integral:floor_function_x}.
\end{example}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-2.5,0) -- (2.5,0) node[right]{$x$};
\draw[axisstyle] (0,-2.5) -- (0,2.5) node[above]{$y$};
% graph of floor function
\draw[linestyle] (-2,-2) -- (-1,-2) -- (-1,-1) -- (0,-1) -- (0,0) --
(1,0) -- (1,1) -- (2,1) -- (2,2);
\end{tikzpicture}
\caption{Plot of the greatest integer function $y = \lfloor x \rfloor$.}
\label{fig:integral:floor_function_x}
\end{figure}

\begin{proof}[Solution]
The function $f(x) = \lfloor x \rfloor$ is not continuous at $x = 1$
in the interval $[1/2, 3/2]$ so the Fundamental Theorem of Calculus
cannot be used. However, we can use our understanding of the meaning
of an integral as an area to obtain
\begin{align*}
&\, \int_{1/2}^{3/2} \lfloor x \rfloor \, dx \\
&=
\text{(area under $y=0$ between $0.5$ and $1$)} +
\text{(area under $y=1$ between $1$ and $1.5$)} \\
&=
0 + 1/2 \\
&=
1/2.
\end{align*}
Now, let's try something illegal: using the Fundamental Theorem of
Calculus to evaluate this. Pretend for the moment that the Fundamental
Theorem of Calculus is valid for discontinuous functions too. Let
\[
F(x) =
\begin{cases}
1, & 1/2 \leq x \leq 1 \\
x, & 1 < x \leq 3/2.
\end{cases}
\]
This function $F$ is continuous and satisfies
$F'(x) = \lfloor x \rfloor$ for all $x$ in $[1/2, 3/2]$ except $x = 1$
(where $f(x) = \lfloor x \rfloor$ is discontinuous). Then $F$ could be
called an ``antiderivative'' of $f$. If we use it to evaluate the
integral, we get
$\int_{1/2}^{3/2} \lfloor x \rfloor \, dx
=
F(x)|_{1/2}^{3/2} = 3/2 - 1 = 1/2$. This is correct. (Surprised?)
Let's try another antiderivative. Let
\[
F(x) =
\begin{cases}
2, & 1/2 \leq x \leq 1 \\
x, & 1 < x \leq 3/2.
\end{cases}
\]
This function $F$ also satisfies $F'(x) = \lfloor x \rfloor$ for all
$x$ in $[1/2, 3/2]$ except $x = 1$. If we use it to evaluate the integral,
we get $\int_{1/2}^{3/2} \lfloor x \rfloor \, dx
= F(x)|_{1/2}^{3/2} = 3/2 - 2 = -1/2$.
This does not have the right sign~(the integral of a non-negative
function must be non-negative), so it must be wrong. The moral of the
story: In general, the Fundamental Theorem of Calculus is false for
discontinuous functions.
\end{proof}

But does such an $F$ as in the Fundamental Theorem of Calculus
(Theorem~\ref{thm:integral:fundamental_theorem_calculus}) always
exist? The surprising answer is ``yes''.

\begin{theorem}
\label{thm:integral:antiderivatives_exist}
Let $F(x) = \int_a^x f(t) dt$. Then $F'(x) = f(x)$ for all $x \in [a, b]$.
\end{theorem}

Note that a nice formula for $F$ can be hard to find or even provably
non-existent. The proof of
Theorem~\ref{thm:integral:antiderivatives_exist} is somewhat
complicated, but is given in complete detail in many calculus
books. You should definitely (no pun intended) read and understand it.

\begin{proof}
(Sketch of proof.) We use the definition of derivative:
%
\begin{align*}
F'(x)
&= \lim_{h \to 0} \frac{F(x+h) - F(x)}{h} \\
&= \lim_{h \to 0} \left.
   \left(\int_a^{x+h} f(t) \, dt - \int_a^x f(t) \, dt \right) \right/ h \\
&= \lim_{h \to 0} \left.
   \left(\int_x^{x+h} f(t) \, dt \right) \right/ h.
\end{align*}
%
Intuitively, for $h$ sufficiently small $f$ is essentially constant,
so $\int_x^{x+h} f(t) \, dt \approx hf(x)$ (this can be made precise
using the extreme value theorem). Thus
\[
\lim_{h \to 0} \left.
\left( \int_x^{x+h} f(t) \, dt \right) \right/ h
= f(x)
\]
which proves the theorem.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Problems ----------------------------------------------------------%%

\subsection{Problems}

In problems 1 to 4, rewrite the limit of each Riemann sum as a
definite integral.

\begin{enumerate}
\item $\lim_{\mesh(P) \to 0} \sum_{i=1}^n (2 + 3c_i) \Delta x_i$ on
  the interval $[0, 4]$.

\item $\lim_{\mesh(P) \to 0} \sum_{i=1}^n \cos(5c_i) \Delta x_i$ on
  the interval $[0, 11]$.

\item $\lim_{\mesh(P) \to 0} \sum_{i=1}^n c_i^3 \Delta x_i$ on the
  interval $[2, 5]$.

\item $\lim_{\mesh(P) \to 0} \sum_{i=1}^n c_i \Delta x_i$ on the
  interval $[2, 5]$.

\item Write as a definite integral, but do not evaluate:
  \begin{itemize}
  \item[(a)] The region bounded by $y = x^3$, the $x$-axis, the line
    $x = 1$, and $x = 5$.

  \item[(b)] The region bounded by $y = \sqrt{x}$, the $x$-axis, and
    the line $x = 9$.
  \end{itemize}

\item Write as a definite integral and \emph{do} evaluate using
  geometry formulas:
  \begin{itemize}
  \item[(a)] The region bounded by $y = 2x$, the $x$-axis, the line $x
    = 1$, and $x = 3$.

  \item[(b)] The region bounded by $y = |x|$, the $x$-axis, and the
    line $x = -1$.
  \end{itemize}

\item For $f(x) = 3 + x$, partition the interval $[0, 2]$ into $n$
  equally wide subintervals of length $\Delta x = 2/n$.
  \begin{itemize}
  \item[(a)] Write the lower sum for this function and partition, and
    calculate the limit of the lower sum as $n \to \infty$.

  \item[(b)] Write the upper sum for this function and partition, and
    compute the limit of the upper sum as $n \to \infty$.
  \end{itemize}

\item For $f(x) = x^3$, partition the interval $[0, 2]$ into $n$
  equally wide subintervals of length $\Delta x = 2/n$.
  \begin{itemize}
  \item[(a)] Write the lower sum for this function and partition, and
    calculate the limit of the lower sum as $n \to \infty$.

  \item[(b)] Write the upper sum for this function and partition, and
    compute the limit of the upper sum as $n \to \infty$.
  \end{itemize}
\end{enumerate}


%%-----------------------------------------------------------------------%%
%%--- Properties of the definite integral -------------------------------%%

\subsection{Properties of the definite integral}

Definite integrals are defined as limits of Riemann sums and they can
be interpreted as areas of geometric regions. This section continues
to emphasize this geometric view of definite integrals and presents
several properties of definite integrals. These properties are
justified using the properties of summations and the definition of a
definite integral as a Riemann sum, but they also have natural
interpretations as properties of areas of regions. These properties
are used in this section to help understand functions that are defined
by integrals. They will be used in future sections to help calculate
the values of definite integrals.

Since integrals are a lot like sums (they are, after all, limits of them),
their properties are similar too. Here is the integral analog of
Theorem~\ref{thm:integral:summation_properties}.

\begin{theorem}
\label{thm:integral:integral_properties}
\textbf{Integral properties.}
\index{integral!properties}
\begin{enumerate}
\item Integral of a constant function:
  $\int_a^b c\, dx = c \cdot (b - a)$.

\item Addition: $\int_a^b (f(x) + g(x)) \, dx
  = \int_a^b f(x) \, dx + \int_a^b g(x) \, dx$.

\item Subtraction: $\int_a^b (f(x) - g(x)) \, dx
  = \int_a^b f(x) \, dx - \int_a^b g(x) \, dx$.

\item Constant multiple: $\int_a^b c \cdot f(x) \, dx
  = c \int_a^b f(x) \, dx$.

\item Preserves positivity: If $f(x) \geq g(x)$ for all $x \in [a,b]$,
  then
  \[
  \int_a^b f(x) \, dx \geq  \int_a^b g(x) \, dx.
  \]
  In particular, if $f(x) \geq 0$ for all $x \in [a, b]$, then
  \[
  \int_a^b f(x) \, dx \geq  0.
  \]

\item Additivity of ranges: $\int_a^b f(x) \, dx +
  \int_b^c f(x) \, dx = \int_a^c f(x) \, dx$.
\end{enumerate}
\end{theorem}

Here are some other properties.

\begin{theorem}
\label{thm:integral:minimum_maximum_integrals}
Let $\min_{x \in [a,b]} f(x)$ and $\max_{x \in [a,b]} f(x)$ be the
minimum and maximum values of $f(x)$, respectively, for
$x \in [a,b]$. Then
\[
(b - a) \cdot \left( \min_{x \in [a,b]} f(x) \right)
\leq
\int_a^b f(x) \, dx
\leq
(b - a) \cdot \left( \max_{x \in [a,b]} f(x) \right).
\]
\end{theorem}

Theorem~\ref{thm:integral:minimum_maximum_integrals} provides lower
and upper bounds for the value of a definite integral. The theorem is
illustrated in Figure~\ref{fig:integral:bounding_definite_integral}.

\begin{figure}[!htbp]
\centering
\subfigure[$(b - a) \cdot \big( \min_{x \in [a, b]} f(x) \big)$]{
\begin{tikzpicture}
[scale=0.8,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded rectangle
\filldraw[fill=gray!25,color=gray!25] (0.7,0) rectangle (5.5831,1);
\draw[linestyle] plot[domain=0.4:5.8831] function{2 + sin(x)};
\draw[linestyle] (0.7,0) -- (0.7,1) -- (5.5831,1) -- (5.5831,0);
\draw[linestyle,dash pattern=on 2pt off 2pt] (0.7,1) -- (0.7,2.6442);
\draw[linestyle,dash pattern=on 2pt off 2pt] (5.5831,1) -- (5.5831,1.3557);
% horizontal axis and tick marks
\draw[axisstyle] (0.4,0) -- (5.8831,0);
\draw[linestyle] (0.7,-0.1) node[below]{$a$} -- (0.7,0);
\draw[linestyle] (5.5831,-0.1) node[below]{$b$} -- (5.5831,0);
% labels
\node () at (3.5,2.6) [] {$f(x)$};
\end{tikzpicture}
}
\quad
\subfigure[$\int_a^b f(x) \, dx$]{
\begin{tikzpicture}
[scale=0.8,%,
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded region
\filldraw[fill=gray!25,color=gray!25]
(0.7,0) -- plot[domain=0.7:5.5831] function{2 + sin(x)} -- (5.5831,0);
\draw[linestyle] plot[domain=0.4:5.8831] function{2 + sin(x)};
\draw[linestyle] (0.7,0) -- (0.7,2.6442);
\draw[linestyle] (5.5831,0) -- (5.5831,1.3557);
% horizontal axis and tick marks
\draw[axisstyle] (0.4,0) -- (5.8831,0);
\draw[linestyle] (0.7,-0.1) node[below]{$a$} -- (0.7,0);
\draw[linestyle] (5.5831,-0.1) node[below]{$b$} -- (5.5831,0);
% labels
\node () at (3.5,2.6) [] {$f(x)$};
\end{tikzpicture}
}
\quad
\subfigure[$(b - a) \cdot \big( \max_{x \in [a,b]} f(x) \big)$]{
\begin{tikzpicture}
[scale=0.8,%,
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% shaded region
\filldraw[fill=gray!25,color=gray!25] (0.7,0) rectangle (5.5831,3);
\draw[linestyle] plot[domain=0.4:5.8831] function{2 + sin(x)};
\draw[linestyle] (0.7,0) -- (0.7,3) -- (5.5831,3) -- (5.5831,0);
% horizontal axis and tick marks
\draw[axisstyle] (0.4,0) -- (5.8831,0);
\draw[linestyle] (0.7,-0.1) node[below]{$a$} -- (0.7,0);
\draw[linestyle] (5.5831,-0.1) node[below]{$b$} -- (5.5831,0);
% labels
\node () at (3.5,2.6) [] {$f(x)$};
\end{tikzpicture}
}
\caption{Bounding the value of a definite integral.}
\label{fig:integral:bounding_definite_integral}
\end{figure}

Which functions are integrable? This important question was finally
answered in the 1850s by Georg Riemann,\index{Riemann, Georg} a name
that should be familiar by now. Riemann proved that a function must be
badly discontinuous to not be integrable.

\begin{theorem}
Every continuous function is integrable. If $f$ is continuous on the
interval $[a, b]$, then
$\lim_{\mesh(P) \to 0} (\sum_{i=1}^n f(c_i) \Delta x_i)$ is always the
same finite number, namely, $\int_a^b f(x) \, dx$, so $f$ is
integrable on $[a, b]$.
\end{theorem}

In fact, a function can have any finite number of breaks and still be
integrable.

\begin{theorem}
Every bounded, piecewise continuous function is integrable. Let $f$ be
defined and bounded (for all $x \in [a, b]$,
$-M \leq f(x) \leq M$ for some $M > 0$), and continuous except at a
finite number of points in $[a, b]$. Then
$\lim_{\mesh(P) \to 0} (\sum_{i=1}^n f(c_i) \Delta x_i)$ is always the
same finite number, namely, $\int_a^b f(x) \, dx$, so $f$ is
integrable on $[a,b]$.
\end{theorem}

\begin{example}
(A nonintegrable function.)\index{nonintegrable function} Though
rarely encountered in everyday practice, there are functions for which
the limit of the Riemann sums does not exist. Those functions are not
integrable. Show that the function
\[
f(x)
=
\begin{cases}
1, & \text{if $x$ is rational} \\
0, & \text{if $x$ is irrational}
\end{cases}
\]
is not integrable on $[0, 1]$.
\end{example}

\begin{proof}[Solution]
For any partition $P$, suppose that you, a very rational (pun
intended) person, always select values of $c_i$ which are rational
numbers. (Every subinterval contains rational numbers and irrational
numbers, so you can always pick $c_i$ to be a rational number.) Then
$f(c_i) = 1$ and your Riemann sum is always
\[
Y_P
=
\sum_{i=1}^n f(c_i) \Delta x_i
=
\sum_{i=1}^n \Delta x_i
=
x_n - x_0
=
1.
\]
However, suppose your friend always selects values of $c_i$ which are
irrational numbers. Then $f(c_i) = 0$ and your friend's Riemann sum is
always
\[
F_P
=
\sum_{i=1}^n f(c_i) \Delta x_i
=
\sum_{i=1}^n 0 \cdot \Delta x_i
=
0.
\]
Now take finer and finer partitions $P$ so that $\mesh(P) \to 0$. Keep
in mind that, no matter how you refine $P$, you can always make
``rational choices'' for $c_i$ and your friend can always make
``irrational choices''. We have $\lim_{\mesh(P) \to 0} Y_P = 1$
and $\lim_{\mesh(P) \to 0} F_P = 0$, so the limit of the Riemann sums
does not have a unique value. Therefore the limit
\[
\lim_{\mesh(P) \to 0} \left( \sum_{i=1}^n f(c_i) \Delta x_i \right)
\]
does not exist, so $f$ is not integrable.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Problems ----------------------------------------------------------%%

\subsection{Problems}

Problems 1 to 19 refer to the graph of $f$ in
Figure~\ref{fig:4-3-13}. Use the graph to determine the values of the
definite integrals. (The bold numbers represent the area of each region.)

\begin{figure}[h!]
\begin{minipage}{\textwidth}
\begin{center}
%\vspace{1.0 cm}
\includegraphics[height=4cm,width=7cm]{fig4-3-13.eps}
\end{center}
\end{minipage}
\caption{Plot for problems.}
\label{fig:4-3-13}
\end{figure}


\begin{enumerate}
\item $\int_0^3 f(x) \, dx$

\item $\int_3^5 f(x) \, dx$

\item $\int_2^2 f(x) \, dx$

\item $\int_6^7 f(x) \, dx$

\item $\int_0^5 f(x) \, dx$

\item $\int_0^7 f(x) \, dx$

\item $\int_3^6 f(x) \, dx$

\item $\int_5^7 f(x) \, dx$

\item $\int_3^0 f(x) \, dx$

\item $\int_5^3 f(x) \, dx$

\item $\int_6^0 f(x) \, dx$

\item $\int_0^3 2f(x) \, dx$

\item $\int_4^4 f(x)^2 \, dx$

\item $\int_0^3 1 + f(t) \, dt$

\item $\int_0^3 x + f(x) \, dx$

\item $\int_3^5 3 + f(x) \, dx$

\item $\int_0^5 2 + f(x) \, dx$

\item $\int_3^5 |f(x)| \, dx$

\item $\int_7^3 1 + |f(x)| \, dx$
\end{enumerate}

For problems 20 to 27, sketch the graph of the integrand function and
use it to help evaluate the integral. (The symbol $|x|$ denotes the
absolute value $x$ and $\lfloor x \rfloor$ denotes the floor function.)

\begin{enumerate}
\addtocounter{enumi}{19}

\item $\int_0^4 |x| \, dx$

\item $\int_0^4 1 + |x| \, dx$

\item $\int_{-1}^2 |x| \, dx$

\item $\int_1^2 |x| - 1 \, dx$

\item $\int_1^3 \lfloor x \rfloor \, dx$

\item $\int_1^{3.5} \lfloor x \rfloor \, dx$

\item $\int_1^3 2 + \lfloor x \rfloor \, dx$

\item $\int_3^1 \lfloor x \rfloor \, dx$
\end{enumerate}


%%-----------------------------------------------------------------------%%
%%--- The trapezoidal rule ----------------------------------------------%%

\subsection{The trapezoidal rule}
\index{trapezoidal rule}

This section includes several techniques for obtaining approximate
numerical values for definite integrals without using
antiderivatives. Mathematically, exact answers are preferable and
satisfying, but for most applications a numerical answer with several
digits of accuracy is just as useful. For instance, suppose you are an
automotive or aircraft designer. You may wish to know how much metal is
required to build your design, created using a computer-aided design
graphics program. Due to the fluctuations in the price for metal, you
only need the approximate cost based on a piecewise linear
approximation to your design. Numerical techniques such as those
discussed in this section can be used for that.

The methods in this section approximate the definite integral of a
function $f$ by building ``easy'' functions close to $f$ and then
exactly evaluating the definite integrals of the ``easy''
functions. If the ``easy'' functions are close enough to $f$, then the
sum of the definite integrals of the ``easy'' functions will be close
to the definite integral of $f$. The left, right, and mid-point
approximations fit horizontal lines to $f$, the ``easy'' functions are
piecewise constant functions and the approximating regions are
rectangles. The \emph{trapezoidal rule} fits slanted lines to $f$,
the ``easy'' functions are piecewise linear, and the approximating
regions are trapezoids. Finally, Simpson's rule fits parabolas to $f$
and the ``easy'' functions are piecewise quadratic polynomials.

All of the methods divide the interval $[a, b]$ into $n$ equally
spaced subintervals. Each subinterval has length
$h = \Delta x_i = \frac{b-a}{n}$ and the points of the partition are
\[
x_0 = a,\, x_1 = a + h,\, x_2 = a + 2h, \dots,
x_i = a + ih, \dots, x_n = a + nh
= a + n \left( \frac{b-a}{n} \right) = b.
\]
If the graph of $f$ is curved, then slanted lines typically come
closer to the graph of $f$ than horizontal ones do and the slanted
lines lead to trapezoidal regions.

The area of a trapezoid is\index{trapezoid area formula}
\[
\text{base} \times \text{average height}
\]
so the area of the trapezoid with coordinates
$(x_0, y_0)$, $(x_0, y_1)$, $(x_1, y_2)$, and $(x_1, y_0)$ is
\[
(x_1 - x_0) \frac{(y_1 - y_0) + (y_2 - y_0)}{2}.
\]
Figure~\ref{fig:integral:trapezoid_coordinates} illustrates a
trapezoid with such coordinates.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick}]
\draw[linestyle] (0,0) node[below]{$(x_0, y_0)$} -- (4,0)
node[below]{$(x_1, y_0)$} -- (4,3) node[above]{$(x_1, y_2)$} -- (0,2)
node[above]{$(x_0, y_1)$} -- cycle;
\end{tikzpicture}
\caption{A trapezoid and its coordinates.}
\label{fig:integral:trapezoid_coordinates}
\end{figure}

\begin{example}
Create and plot a piecewise linear function describing the trapezoidal
approximation to the area under $y = x^3 - 3x^2 + 2x$.
\end{example}
%
\begin{proof}[Solution]
The following code constructs and plots the trapezoidal approximation
to the integral $\int_0^2 x^3 - 3x^2 + 2x \, dx$:
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: x = var("x")
sage: f1 = lambda x: x^3 - 3*x^2 + 2*x
sage: f2 = Piecewise([[(0, 2), f1]])
sage: f3 = f2.trapezoid(4)
sage: P1 = list_plot([(1/2, 0), (0.5, f2(0.5))], plotjoined=True, linestyle=":")
sage: P2 = list_plot([(3/2, 0), (1.5, f2(1.5))], plotjoined=True, linestyle=":")
sage: P3 = plot(f2)
sage: P4 = plot(f3)
sage: show(P1 + P2 + P3 + P4)
sage: f2.trapezoid_integral_approximation(4)
0
sage: integrate(x^3 - 3*x^2 + 2*x, x, 0, 2)
0
\end{lstlisting}
\end{center}
%
The plot of this trapezoidal approximation is shown in
Figure~\ref{fig:integral:trapezoidal_rule}. We got lucky here since
both the integral and its trapezoidal approximation actually have the
same value.
\end{proof}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=4,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.1,0) -- (2.1,0) node[right]{$x$};
\draw[axisstyle] (0,-0.5) -- (0,0.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (0.5,-0.025) node[below]{0.5} -- (0.5,0.025);
\draw[linestyle] (1,-0.025) node[below]{1} -- (1,0.025);
\draw[linestyle] (1.5,-0.025) -- (1.5,0.025) node[above]{1.5};
\draw[linestyle] (2,-0.025) -- (2,0.025) node[above]{2};
% tick marks on vertical axis
\draw[linestyle] (-0.025,-0.4) node[left]{$-0.4$} -- (0.025,-0.4);
\draw[linestyle] (-0.025,-0.2) node[left]{$-0.2$} -- (0.025,-0.2);
\draw[linestyle] (-0.025,0.2) node[left]{0.2} -- (0.025,0.2);
\draw[linestyle] (-0.025,0.4) node[left]{0.4} -- (0.025,0.4);
% graphs of functions
\draw[linestyle] plot[domain=0:2] function{x**3 - 3*x**2 + 2*x};
\draw[linestyle] (0,0) -- (0.5,0.375) -- (1.5,-0.375) -- (2,0);
\draw[linestyle,dash pattern=on 2pt off 2pt] (0.5,0) -- (0.5,0.375);
\draw[linestyle,dash pattern=on 2pt off 2pt] (1.5,0) -- (1.5,-0.375);
\end{tikzpicture}
\caption{A trapezoidal approximation to the integral
  $\int_0^2 x^3 - 3x^2 + 2x \, dx$.}
\label{fig:integral:trapezoidal_rule}
\end{figure}

The trapezoidal rule for approximating a definite integral is
formalized in
Theorem~\ref{thm:integral:trapezoidal_approximation_rule}.

\begin{theorem}
\label{thm:integral:trapezoidal_approximation_rule}
\textbf{Trapezoidal approximation rule.}
\index{trapezoidal rule}
Let $f$ be integrable on $[a, b]$ and partition $[a, b]$ into $n$
subintervals each of length $h = \frac{b-a}{n}$. Then the trapezoidal
approximation of $\int_a^b f(x) \, dx$ is
\[
T_n
=
\frac{h}{2} \big[
  f(x_0) + 2 f(x_1) + 2 f(x_2) + \cdots + 2 f(x_{n-1}) + f(x_n)
\big].
\]
\end{theorem}

\begin{proof}
The area of the trapezoid with coordinates
$(x_i, 0)$, $(x_i, y_i)$, $(x_{i+1}, 0)$, $(x_{i+1}, y_{i+1})$,
where $y_i = f(x_i)$, is $(x_{i+1} - x_i) \frac{y_i + y_{i+1}}{2}
= \frac{h}{2} \cdot (y_i + y_{i+1})$. Therefore, the sum of the
trapezoidal areas approximating $\int_a^b f(x) \, dx$ is
\[
\sum_{i=0}^{n-1} (x_{i+1} - x_i) \frac{y_i + y_{i+1}}{2}
=
\frac{h}{2} \cdot \sum_{i=0}^{n-1} (y_i + y_{i+1})
=
\frac{h}{2} \cdot (y_0 + 2y_1 + \cdots + 2y_{n-1} + y_n)
\]
as desired.
\end{proof}

\begin{table}[!htbp]
\centering
\begin{tabular}{|c|c|} \hline
$x$ & $f(x)$ \\\hline\hline
1.0 & 4.2    \\
1.5 & 3.4    \\
2.0 & 2.8    \\
2.5 & 3.6    \\
3.0 & 3.2    \\ \hline
\end{tabular}
\caption{Tabulated values for the $T_4$ approximation of
  $\int_1^3 f(x) \, dx$.}
\label{tab:integral:tabulated_values_T_4}
\end{table}

\begin{example}
\label{ex:integral:T_4_trapezoidal_approximation}
Calculate $T_4$, the trapezoidal approximation of
$\int_1^3 f(x) \, dx$, for the function values tabulated in
Table~\ref{tab:integral:tabulated_values_T_4}.
\end{example}

\begin{proof}[Solution]
The step size is $h = (b - a) / n = (3 - 1) / 4 = 1/2$. Then
%
\begin{align*}
T_4
&= \frac{h}{2} \big[ f(x_0) + 2f(x_1) + 2f(x_2) + 2f(x_3) + f(x_4) \big] \\
&= \frac{1}{4} \big[ 4.2 + 2(3.4) + 2(2.8) + 2(3.6) + (3.2) \big] \\
&= (0.25)(27)
\end{align*}
%
which simplifies to $6.75$.
\end{proof}

\begin{example}
Let's see how well the trapezoidal rule approximates an integral whose
exact value we know, i.e. $\int_1^3 x^2 \, dx = \frac{26}{3}$.
Calculate $T_4$, the trapezoidal approximation of $\int_1^3 x^2 \, dx$.
\end{example}

\begin{proof}[Solution]
As in Example~\ref{ex:integral:T_4_trapezoidal_approximation},
$h = 0.5$ and $x_0 = 1$, $x_1 = 1.5$, $x_2 = 2$, $x_3 = 2.5$, and
$x_4 = 3$. Then
%
\begin{align*}
T_4
&= \frac{h}{2} \big[ f(x_0) + 2f(x_1) + 2f(x_2) + 2f(x_3) + f(x_4) \big] \\
&= 0.5 \big[ f(1) + 2f(1.5) + 2f(2) + 2f(2.5) + f(3) \big] \\
&= (0.25) \big[ 1 + 2(2.25) + 2(4) + 2(6.25) + 9 \big] \\
&= 8.75.
\end{align*}
%
Using \sage, one can show that $T_{10} = 217/25 = 8.68$,
$T_{100} = 21667/2500 = 8.6668$, and
$T_{1000} = 2166667/250000=8.666668$. These trapezoidal approximations
are indeed approaching the value $8.666\dots$ of the integral.
\end{proof}

\begin{example}
Use Python and/or \sage to compute a trapezoidal approximation to the
definite integral $\int_0^1 \sin(x) \, dx$.
\end{example}

\begin{proof}[Solution]
Here is a Python program illustrating the trapezoidal rule:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
f = lambda x: sin(x)
def trapezoidal_rule(fcn, a, b, n):
    """
    Does computation of the trapezoidal rule approximation of the
    definite integral int_a^b fcn(x) dx using n steps.
    """
    Deltax = (b - a)*1.0 / n
    coeffs = [2] * (n - 1)
    coeffs = [1] + coeffs + [1]
    valsf = [f(a + Deltax*i) for i in range(n + 1)]
    return (Deltax / 2) * sum([coeffs[i] * valsf[i] for i in range(n + 1)])
\end{lstlisting}
\end{center}
%
Now we paste this into \sage (you may instead paste into Python if you
wish) and see how it works.
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: f = lambda x: sin(x)
sage: def trapezoidal_rule(fcn, a, b, n):
....:     """
....:     Does computation of the trapezoidal rule approximation of the
....:     definite integral int_a^b fcn(x) dx using n steps.
....:     """
....:     Deltax = (b - a)*1.0 / n
....:     coeffs = [2] * (n - 1)
....:     coeffs = [1] + coeffs + [1]
....:     valsf = [f(a + Deltax*i) for i in range(n + 1)]
....:     return (Deltax / 2) * sum([coeffs[i] * valsf[i] for i in range(n + 1)])
....:
sage: integral(f(x), x, 0, 1)
-cos(1) + 1
sage: RR(integral(f(x), x, 0, 1))
0.459697694131860
sage: trapezoidal_rule(f(x), 0, 1, 4)
0.457300937571502
\end{lstlisting}
\end{center}
%
Note that $\int_0^1 \sin(x) \, dx = 1 - \cos(1) = 0.459\dots$, whereas
the trapezoidal rule gives the approximation $T_4 = 0.457\dots$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Simpson's rule ----------------------------------------------------%%

\subsection{Simpson's rule}
\index{Simpson's rule}

If the graph of $f$ is curved, even the slanted lines may not fit the
graph of $f$ as closely as we would like, and a large number of
subintervals may still be needed with the trapezoidal rule to get a
good approximation of the definite integral. Curves typically fit the
graph of $f$ better than straight lines. The easiest nonlinear curves
are parabolas.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=4,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal axis
\draw[axisstyle] (0.9,0) -- (2.6,0);
% graph of function
\draw[linestyle] plot[domain=1:2.5] function{sin(x)};
% dash lines
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,0.8414)
node[above left]{$(x_0, y_0)$};
\draw[linestyle,dash pattern=on 2pt off 2pt] (1.75,0) -- (1.75,0.9839)
node[above right]{$(x_1, y_1)$};
\draw[linestyle,dash pattern=on 2pt off 2pt] (2.5,0) -- (2.5,0.5984)
node[above right]{$(x_2, y_2)$};
% labels
\end{tikzpicture}
\caption{Three points on a parabola.}
\label{fig:integral:three_points_on_parabola}
\end{figure}

\begin{theorem}
\label{thm:integral:three_points_on_parabola}
Three points $(x_0, y_0)$, $(x_1, y_1)$, and $(x_2, y_2)$ are needed
to determine the equation of a parabola. The area under a parabolic
region with evenly spaced $x_i$ values is
\[
\frac{\Delta x}{3} (y_0 + 4y_1 + y_2).
\]
\end{theorem}

Figure~\ref{fig:integral:three_points_on_parabola} illustrates
Theorem~\ref{thm:integral:three_points_on_parabola}. The next theorem
provides a method for approximating a definite integral using
points on a parabola.

\begin{theorem}
\textbf{Simpson's rule.}
Let $f$ be integrable on $[a, b]$ and partition $[a, b]$ into an even
number $n$ of subintervals each of length
$h = \Delta x = \frac{b-a}{n}$. Then the parabolic approximation of
$\int_a^b f(x) \, dx$ is
\[
S_n
=
\frac{\Delta x}{3} \big[
  f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + 2f(x_4) + \cdots +
  4f(x_{n-1}) + f(x_n) \big].
\]
\end{theorem}

\begin{example}
\label{ex:integral:S_4_Simpson_rule_approximation}
Calculate $S_4$, Simpson's rule approximation of
$\int_1^3 f(x) \, dx$, for the function values tabulated in
Table~\ref{tab:integral:tabulated_values_T_4}.
\end{example}

\begin{proof}[Solution]
The step size is $h = (b - a) / n = (3 - 1) / 4 = 1 / 2$. Then
%
\begin{align*}
S_4
&= \frac{h}{3} \big[ f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + f(x_4) \big] \\
&= \frac{1}{6} \big[ 4.2 + 4(3.4) + 2(2.8) + 4(3.6) + (3.2) \big] \\
&= \frac{41}{6}
\end{align*}
%
which is approximately $6.83\dots$.
\end{proof}

\begin{example}
Use \sage and/or Python to compute an approximation to the integral
$\int_0^1 \sin(x) \, dx$ using Simpson's rule.
\end{example}

\begin{proof}[Solution]
Here is a Python program to illustrate Simpson's rule:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
f = lambda x: sin(x)
def simpsons_rule(fcn, a, b, n):
    Deltax = (b - a)*1.0 / n
    n2 = int(n / 2)
    coeffs = [4, 2] * n2
    coeffs = [1] + coeffs[:n-1] + [1]
    valsf = [f(a + Deltax*i) for i in range(n + 1)]
    return (Deltax / 3) * sum([coeffs[i] * valsf[i] for i in range(n + 1)])
\end{lstlisting}
\end{center}
%
Now we paste this into \sage and see how it works:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: def simpsons_rule(fcn, a, b, n):
....:     Deltax = (b - a)*1.0 / n
....:     n2 = int(n / 2)
....:     coeffs = [4, 2] * n2
....:     coeffs = [1] + coeffs[:n-1] + [1]
....:     valsf = [f(a + Deltax*i) for i in range(n + 1)]
....:     return (Deltax / 3) * sum([coeffs[i] * valsf[i] for i in range(n + 1)])
....:
sage: integral(f(x), x, 0, 1)
-cos(1) + 1
sage: RR(integral(f(x), x, 0, 1))
0.459697694131860
sage: simpsons_rule(f(x), 0, 1, 4)
0.459707744927311
sage: RR(simpsons_rule(f(x), 0, 1, 4))
0.459707744927311
sage: RR(simpsons_rule(f(x), 0, 1, 10))
0.459697949823821
\end{lstlisting}
\end{center}
%
To paste this into Python, you must first import the \verb!sin! function.
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
>>> from math import sin
>>> f = lambda x: sin(x)
>>> def simpsons_rule(fcn, a, b, n):
...     Deltax = (b - a)*1.0 / n
...     n2 = int(n / 2)
...     coeffs = [4, 2] * n2
...     coeffs = [1] + coeffs[:n-1] + [1]
...     valsf = [f(a + Deltax*i) for i in range(n + 1)]
...     return (Deltax / 3) * sum([coeffs[i] * valsf[i] for i in range(n + 1)])
...
>>> simpsons_rule(f, 0, 1, 4)
0.45970774492731092
\end{lstlisting}
\end{center}
%
Using this and the trapezoidal approximation function, we can compare
which is best in this example.
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: simpsons_rule(f(x), 0, 1, 4)
0.459707744927311
sage: trapezoidal_rule(f(x), 0, 1, 4)
0.457300937571502
sage: simpsons_rule(f(x), 0, 1, 10)
0.459697949823821
sage: trapezoidal_rule(f(x), 0, 1, 10)
0.459314548857976
sage: integral(f(x), x, 0, 1)
-cos(1) + 1
sage: RR(integral(f(x), x, 0, 1))
0.459697694131860
\end{lstlisting}
\end{center}
%
In this case, we see that Simpson's rule wins every time.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Trapezoidal vs. Simpson: Which method is best ---------------------%%

\subsection{Trapezoidal vs. Simpson: Which method is best?}

The hardest and slowest part of approximations by trapezoidal or
Simpson's rules, whether by hand or by computer, is the evaluation of
the function at the $x_i$ values. For $n$ subintervals, both methods
require about the same number of function evaluations. The rest of
this section discusses \emph{error bounds} of the approximations so we
know how close our approximation is to the exact value of the integral
even if we do not know the exact value.

\begin{theorem}
\textbf{Error bound for trapezoidal approximation.}
\index{trapezoidal rule}
If the second derivative of $f$ is continuous on $[a, b]$ and
$M_2 \geq \max_{x \in [a,b]} | f ''(x) |$, then the error of the
$T_n$ approximation is
\[
\left| \int_a^b f(x) \, dx - T_n \right|
\leq
\frac{(b - a)^3}{12n^2} M_2.
\]
\end{theorem}

The \emph{error bound}\index{error bound} formula
$\frac{(b - a)^3}{12n^2} M_2$ for the trapezoidal approximation is a
\emph{guarantee}: the actual error is guaranteed to be no larger than
the error bound. In fact, the actual error is usually much smaller
than the error bound. The word \emph{error} does not indicate a
mistake. It means the deviation or distance from the exact answer.

\begin{example}
How large must $n$ be to be certain that $T_n$ is within $0.001$ of
$\int_0^1 \sin(x) \, dx$?
\end{example}

\begin{proof}[Solution]
We want to pick $n$ so that
$\frac{(b - a)^3}{12n^2} M_2 \leq 1/1000$. We may take $M_2 = 1$, so
$\frac{(b - a)^3}{12n^2} M_2 =
\frac{1}{12n^2} \leq 1/1000$ or $n^2 \geq 1000/12$. Taking $n = 10$
will work.
\end{proof}

\begin{theorem}
\textbf{Error bound for Simpson's rule approximation.}
\index{Simpson's rule}
If the fourth derivative of $f$ is continuous on $[a, b]$ and
$M_4 \geq \max_{x \in [a,b]} | f^{(4)}(x) |$, then the error of the
$S_n$ approximation is
\[
\left| \int_a^b f(x) \, dx - S_n \right|
\leq
\frac{(b - a)^5}{180n^4} M_4.
\]
\end{theorem}

\begin{example}
How large must $n$ be to be certain that $S_n$ is within $0.001$ of
$\int_0^1 \sin(x) \, dx$?
\end{example}

\begin{proof}[Solution]
We want to pick $n$ so that $\frac{(b - a)^5}{180n^4} M_2 \leq 1/1000$.
We may take $M_2 = 1$, so $\frac{(b - a)^5}{180n^4} M_4 =
\frac{1}{180n^4} \leq 1/1000$ or $n^4 \geq 1000/180$. Taking $n = 2$
will work.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Areas, integrals, and antiderivatives -----------------------------%%

\section{Areas, integrals, and antiderivatives}

This section explores properties of functions defined as areas and
examines some of the connections among areas, integrals, and
antiderivatives. In order to focus on the geometric meaning and
connections, all of the functions in this section are nonnegative, but
the results are generalized in the next section and proved true for
all continuous functions. This section also presents examples to
illustrate how areas, integrals, and antiderivatives can are
used. When $f$ is a continuous, nonnegative function, then the area
function $A(x) = \int_a^x f(t) \, dt$ represents the area between the
graph of $f$, the $t$-axis, and between the vertical lines at $t = a$
and $t = x$ (see Figure~\ref{fig:integral:plot_area_function}), and
the derivative of $A(x)$ represents the rate of change (growth) of
$A(x)$.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth},%
  arrowstyle/.style={semithick,->,>=stealth}]
% shaded function
\filldraw[fill=gray!25,color=gray!25]
(1.2,0.2) -- plot[domain=1.2:4.8] function{x + sin(x)} -- (4.8,0.2);
\draw[linestyle] plot[domain=0.9:5.2] function{x + sin(x)};
\draw[linestyle] (1.2,0.2) -- (1.2,2.132);
\draw[linestyle] (4.8,0.2) -- (4.8,3.8038);
% horizontal axis
\draw[axisstyle] (-0.2,0.2) -- (5.8,0.2) node[right]{$t$};
\draw[axisstyle] (0.2,-0.2) -- (0.2,4.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1.2,0.1) node[below]{$a$} -- (1.2,0.3);
\draw[linestyle] (4.8,0.1) node[below]{$x$} -- (4.8,0.3);
% labels
\node () at (3,4) [] {$y = f(t)$};
\node (A) at (6,2.3) [] {$A(x)$};
\node (B) at (4,2.3) {} {};
\path (A) edge[arrowstyle] (B);
\end{tikzpicture}
\caption{Plot of an area function.}
\label{fig:integral:plot_area_function}
\end{figure}

Let $F(x)$ be a differentiable function. Call $F(x)$ an
\emph{antiderivative}\index{antiderivative} of $f(x)$ if
$\frac{d}{dx} F(x) = f(x)$. We have seen examples which showed that,
at least for \emph{some} functions $f$, the derivative of $A(x)$ was
equal to $f$ so $A(x)$ was an antiderivative of $f$. The next theorem
says the result is true for every continuous, nonnegative function
$f$.

\begin{theorem}
\label{thm:integral:area_function_antiderivative}
\textbf{The area function is an antiderivative.}
\index{area!as antiderivative}
Let $f$ be a continuous nonnegative function, $x \geq a$,
and $A(x) = \int_a^x f(t) \, dt$. Then
$\frac{d}{dx} \int_a^x f(t) \, dt = \frac{d}{dx} A(x) = f(x)$,
so $A(x)$ is an antiderivative of $f(x)$.
\end{theorem}

This result relating integrals and antiderivatives is a special case
(for nonnegative functions $f$) of the Fundamental Theorem of Calculus.
Theorem~\ref{thm:integral:area_function_antiderivative} is important
for two reasons:
%
\begin{enumerate}
\item it says that a large collection of functions have antiderivatives; and

\item it leads to an easy way of exactly evaluating definite integrals.
\end{enumerate}

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[scale=1.2,%
  linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (6.7,0) node[right]{$x$};
\draw[axisstyle] (0,-1.5) -- (0,1.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (2,-0.1) -- (2,0.1) node[above]{2};
\draw[linestyle] (4,-0.1) -- (4,0.1) node[above]{4};
\draw[linestyle] (6,-0.1) -- (6,0.1) node[above]{6};
% tick marks on vertical axis
\draw[linestyle] (-0.1,-1) node[left]{$-1$} -- (0.1,-1);
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
% graphs of function
\draw[linestyle] plot[domain=0:6.29] function{sin(x)};
\draw[linestyle,dash pattern=on 2pt off 2pt] plot[domain=0:6.29]
function{cos(x)};
% labels
\node () at (2.3,1.3) [] {$y = A(x) = \sin(x)$};
\node () at (5.7,1.3) [] {$y = G(x) = \cos(x)$};
\end{tikzpicture}
\caption{Plot of $y = \int_0^x G(t) \, dt$ and $y = G(x)$.}
\label{fig:integral:sin_x_antiderivative_cos_x}
\end{figure}

\begin{example}
Let $G(x) = \frac{d}{dx} \int_0^x \cos(t) \, dt$. Evaluate $G(x)$ for
$x = \pi/4$, $\pi/2$, and $3\pi/4$.
\end{example}

\begin{proof}[Solution]
It is not hard to plot the graph of
$A(x) = \int_0^x \cos(t) \, dt = \sin(x)$ (see
Figure~\ref{fig:integral:sin_x_antiderivative_cos_x}). By
Theorem~\ref{thm:integral:area_function_antiderivative},
$A'(x) = G(x) = \cos(x)$ so $A'(\pi/4) = \cos(\pi/4) = 0.707\dots$,
$A'(\pi/2) = \cos(\pi/2) = 0$, and $A'(3\pi/4) = \cos(3π/4) = -0.707\dots$.
%
Figure~\ref{fig:integral:sin_x_antiderivative_cos_x} shows a plot of
$y = A(x)$ and $y = G(x)$, which can be created using the following
\sage commands:
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: P = plot(cos(x), x, 0, 2*pi, linestyle="--")
sage: Q = plot(sin(x), x, 0, 2*pi)
sage: R = text("$y = A(x) = \sin(x)$", (3.1, 1))
sage: S = text("$y = G(x) = \cos(x)$", (6.8, 0.7))
sage: show(P + Q + R + S)
\end{lstlisting}
\end{center}
\end{proof}

\begin{theorem}
\textbf{Antiderivatives and definite integrals.}
Let $f$ be a continuous, nonnegative function and let $F$ be any
antiderivative of $f$ (i.e. $F'(x) = f(x)$) on the interval $[a, b]$.
Then
\begin{center}
\begin{tabular}{|l|} \hline
area bounded between the graph \\
of $f$, the $x$-axis, and vertical \\
lines at $x = a$ and $x = b$ \\\hline
\end{tabular}
$ =  \displaystyle{\int_a^b} f(x) \, dx = F(b) - F(a)$.
\end{center}
\end{theorem}

The problem of finding the exact value of a definite integral reduces
to finding some (any) antiderivative $F$ of the integrand and then
evaluating $F(b) - F(a)$. Even finding one antiderivative can be
difficult and, for now, we will stick to functions which have easy
antiderivatives. Later we will explore some methods for finding
antiderivatives of more complicated functions. The evaluation
$F(b) - F(a)$ is represented by the symbol $F(x)|_a^b$.

\begin{example}
\label{ex:integral:evaluate_integral_two_ways}
Evaluate $\int_1^3 x \, dx$ in two ways:
%
\begin{itemize}
\item[(a)] By sketching the graph of $y = x$ and geometrically finding
  the area.

\item[(b)] By finding an antiderivative $F(x)$ of $f$ and evaluating
  $F(3) - F(1)$.
\end{itemize}
\end{example}

\begin{proof}[Solution]
(a) The graph of $y = x$ is a straight line. The shape is a triangle
whose geometrical formula (area $= \frac{1}{2} bh$) tells us that the
area is $4$.

(b) One antiderivative of $x$ is $F(x) = \frac{1}{2} x^2$ (check that
$\frac{d}{dx} (\frac{1}{2} x^2) = x$) and
\[
F(x)|_1^3
=
F(3) - F(1)
=
\frac{1}{2} 3^2 - \frac{1}{2} 1^2
=
4
\]
which agrees with part~(a). Suppose someone chose another
antiderivative of $x$, say $F(x) = \frac{1}{2} x^2 + 7$ (check that
$\frac{d}{dx} (\frac{1}{2} x^2 + 7) = x$), then
\[
F(x)|_1^3
=
F(3) - F(1)
=
\left( \frac{1}{2} 3^2 + 7 \right) -
\left( \frac{1}{2} 1^2 + 7 \right)
=
4.
\]
No matter which antiderivative $F$ is chosen, $F(3) - F(1)$ equals $4$.
\end{proof}

\begin{practice}
Evaluate $\int_1^3 (x - 1) \, dx$ in the two ways of
Example~\ref{ex:integral:evaluate_integral_two_ways}.
\end{practice}

\begin{practice}
Find the area between the graph of $y = 3x^2$ and the horizontal
axis for $x$ between $1$ and $2$.
\end{practice}


%%-----------------------------------------------------------------------%%
%%--- Integrals, antiderivatives, and applications ----------------------%%

\subsection{Integrals, antiderivatives, and applications}

The antiderivative method of evaluating definite integrals can also be
used when we need to find an area. It is also useful for solving
applied problems.

\begin{example}
Suppose that $t$ minutes after putting $1000$ bacteria on a petri
plate, the growth rate  of the population is $6t$ bacteria per minute.
%
\begin{itemize}
\item[(a)] How many new bacteria are added to the population during
  the first $7$ minutes?

\item[(b)] What is the total population after $7$ minutes?

\item[(c)] When will the total population be $2200$ bacteria?
\end{itemize}
\end{example}

\begin{proof}[Solution]
(a) The number of new bacteria is the area under the growth rate graph.
One antiderivative of $6t$ is $3t^2$ (check that
$\frac{d}{dx} (3t^2) = 6t$). The number of new bacteria during the
first 7 minutes is $\int_0^7 6t \, dt = 3t^2|_0^7 = 147$.

(b) The new population is equal to the addition of the old population
and the new bacteria. Then the total bacteria population after 7
minutes is $1000 + 147 = 1147$ bacteria.

(c) If the total population is $2200$ bacteria, then there are
$2200 - 1000 = 1200$ new bacteria. We need to find the time $T$ needed
for that many new bacteria to occur. Then $1200$ new bacteria is equal
to $\int_0^T 6t \, dt = 3t^2|_0^T = 3(T)^2 - 3(0)^2 = 3 T^2$ so
$T^2 = 400$ and $T = 20$ minutes. After $20$ minutes, the total
bacteria population will be $1000 + 1200 = 2200$.
\end{proof}

\begin{practice}
A robot has been programmed so that when it starts to move, its
velocity after $t$ seconds will be $3t^2$ feet/second.
%
\begin{itemize}
\item[(a)] How far will the robot travel during its first 4 seconds of
  movement?

\item[(b)] How far will the robot travel during its next 4 seconds of
  movement?

\item[(c)] How many seconds before the robot is 729 feet from its
  starting place?
\end{itemize}
%
[Hint: an antiderivative of $3t^2$ is $t^3$.]
\end{practice}

\begin{practice}
The velocity of a car after $t$ seconds is $2t$ feet per second.
%
\begin{itemize}
\item[(a)] How far does the car travel during its first 10 seconds?

\item[(b)] How many seconds does it take the car to travel half the
  distance in part~(a)?
\end{itemize}
\end{practice}

Calculus is important for many reasons, but students are usually
required to study calculus because it is needed for understanding
concepts and doing applications in a variety of fields. The
Fundamental Theorem of Calculus is very important to both pursuits.

Most applied problems in integral calculus require the following steps
to get from the problem to a numerical answer. We start with an
applied problem and derive a Riemann sum from the problem. We evaluate
the Riemann sum using a definite integral to obtain a numerical
answer. In some cases, the path from the problem to the answer may be
abbreviated, but the steps from problem to Riemann sum, from Riemann
sum to definite integral, and from definite integral to a numeric
answer, are commonly used.


%%-----------------------------------------------------------------------%%
%%--- Indefinite integrals and net change -------------------------------%%

\subsection{Indefinite integrals and net change}

We have seen how integrals can be interpreted using area. In this
section, we will see how integrals can be interpreted physically as
the \emph{net change}\index{net change} of a quantity.

The notation $\int f(x) \, dx  = F(x)$ means that $F'(x) = f(x)$ on
some (usually specified) domain of definition of $f(x)$. Recall that
we call such an $F(x)$ an antiderivative of $f(x)$.
\index{antiderivative}

\begin{proposition}
\label{prop:integral:two_antiderivatives_differ_constant}
Suppose $f$ is a continuous function on an open interval $(a, b)$.
Then any two antiderivatives differ by a constant.
\end{proposition}

\begin{proof}
If $F_1(x)$ and $F_2(x)$ are both antiderivatives of a function
$f(x)$, then
\[
\big( F_1(x) - F_2(x) \big)'
=
F_1'(x) - F_2'(x)
=
f(x) - f(x)
=
0.
\]
Thus $F_1(x) - F_2(x) = c$ for some constant $c$ (since only constant
functions have slope~$0$ everywhere). Thus $F_1(x) = F_2(x) + c$ as
claimed.
\end{proof}

Due to
Proposition~\ref{prop:integral:two_antiderivatives_differ_constant},
we often write
\[
\int f(x) \, dx = F(x) + C
\]
where $C$ is an unspecified constant. Note that the proposition need
not be true if $f$ is not defined on a whole interval. For example,
$f(x) = 1/x$ is not defined at $0$.  For any pair of constants $c_1$
and $c_2$, the function
\[
F(x)
=
\begin{cases}
\ln(|x|) + c_1, & x < 0,\\
\ln(x) + c_2,   & x > 0
\end{cases}
\]
satisfies $F'(x) = f(x)$ for all $x \neq 0$. We often still just write
$\int 1/x = \ln(|x|) + c$ anyway, meaning that this formula is
supposed to hold only on one of the intervals on which $1/x$ is
defined (e.g. on $(-\infty, 0)$ or $(0, \infty)$).

Now we pause to emphasize the notation difference between definite and
indefinite integration:
%
\begin{align*}
\int_a^b f(x) \, dx &= \text{a specific number} \\
\int f(x) \, dx &= \text{a (family of) functions}
\end{align*}
%
There are no small families in the world of antiderivatives. If $f$
has one antiderivative $F$ (as it always does, unless $f$ is a really
unusual function), then $f$ has an infinite number of antiderivatives
and every one of them has the form $F(x) + C$.

\begin{example}
There are many ways to write a particular indefinite integral and some
of them may look very different. You can check that
$F(x) = \sin (x)^2$, $G(x) = -\cos (x)^2$, and
$H(x) = 2\sin (x)^2 + \cos (x)^2$ all have the same derivative
$f(x) = 2\sin(x) \cos(x)$. Then the indefinite integral of
$2\sin(x) \cos(x)$, i.e. $\int 2\sin(x) \cos(x) \, dx$, can be written
in several ways: $\sin (x)^2 + C$, or $-\cos (x)^2 + C$, or
$2\sin (x)^2 + \cos (x)^2 + C$.
\end{example}

One of the \emph{main goals} of this book is to help you to get
really good at computing $\int f(x) \,dx$ for various functions
$f(x)$. It is useful to memorize a table of integrals, such as the
one below, since often the trick to integration is to relate a given
integral to one you know. Integration is like solving a puzzle or
playing a game and often you win by moving into a position where you
know how to defeat your opponent, e.g. relating your integral to
integrals that you already know how to do.  If you know how to do a
basic collection of integrals, it will be easier for you to see how to
get to a known integral from an unknown one.

Whenever you successfully compute $F(x) = \int f(x) \, dx$, then you
have constructed a \emph{mathematical gadget} that allows you to very
quickly compute $\int_a^b f(x) \, dx$ for any $a,b$ (in the interval of
definition of $f(x)$).  The gadget is $F(b) - F(a)$.  This is really
powerful.

\begin{example}
Find the indefinite integrals of $x^2 + 1 + \frac{1}{x^2 + 1}$,
$\sqrt{\frac{5}{x}}$, and $\frac{\sin(2x)}{\sin(x)}$.
\end{example}

\begin{proof}[Solution]
The indefinite integral of $x^2 + 1 + \frac{1}{x^2 + 1}$ is
%
\begin{align*}
\int x^2 + 1 + \frac{1}{x^2 + 1} \, dx
&= \int x^2 \, dx  + \int 1 \, dx  + \int \frac{1}{x^2 + 1} \, dx \\
&= \frac{1}{3} x^2 + x + \tan^{-1}(x) + c.
\end{align*}
%
The indefinite integral of $\sqrt{\frac{5}{x}}$ is
\[
\int \sqrt{\frac{5}{x}} \, dx
=
\int \sqrt{5} x^{-1/2} \, dx
=
2 \sqrt{5} x^{1/2} + c
\]
and the indefinite integral of $\frac{\sin(2x)}{\sin(x)}$ is
\[
\int \frac{\sin(2x)}{\sin(x)} \, dx
=
\int \frac{2 \sin(x) \cos(x)} {\sin(x)} \, dx
=
\int 2 \cos(x) \, dx
=
2 \sin(x) + c
\]
for some constant $c$.
\end{proof}

Here is a table of some common
antiderivatives.\index{antiderivative!table} You can verify the
following yourself.


\subsubsection*{Constant function}

\begin{enumerate}
\item $\displaystyle{\int k \, dx = kx + C}$
\end{enumerate}


\subsubsection*{Powers of $x$}

\begin{enumerate}
\addtocounter{enumi}{1}
\item $\displaystyle{\int x^n \, dx = \frac{x^{n + 1}}{n + 1} + C}$
  for $n \neq -1$

\item $\displaystyle{\int x^{-1} \, dx = \ln(x) + C}$
\end{enumerate}


\subsubsection*{Common special cases}

\begin{enumerate}
\addtocounter{enumi}{3}
\item $\displaystyle{\int \sqrt{x} \, dx = \frac{2}{3} x^{3/2} + C}$

\item $\displaystyle{\int \frac{1}{\sqrt{x}} \, dx = 2x^{1/2} + C}$
\end{enumerate}


\subsubsection*{Trigonometric functions}

\begin{enumerate}
\addtocounter{enumi}{5}
\item $\displaystyle{\int \cos(ax) \, dx = \frac{1}{a}\sin(x) + C}$

\item $\displaystyle{\int \sin(ax) \, dx = -\frac{1}{a}\cos(x) + C}$

\item $\displaystyle{\int \sec(ax)^2 \, dx = \frac{1}{a}\tan(x) + C}$

\item $\displaystyle{\int \csc(ax)^2 \, dx = -\frac{1}{a}\cot(x) + C}$

\item $\displaystyle{\int \sec(ax)\tan(x) \, dx = \frac{1}{a}\sec(x) + C}$

\item $\displaystyle{\int \csc(ax)\cot(x) \, dx = -\frac{1}{a}\csc(x) + C}$
\end{enumerate}


\subsubsection*{Common special cases}

\begin{enumerate}
\addtocounter{enumi}{11}
\item $\displaystyle{\int \cos(x) \, dx = \sin(x) + C}$

\item $\displaystyle{\int \sin(x) \, dx = -\cos(x) + C}$
\end{enumerate}


%%-----------------------------------------------------------------------%%
%%--- Physical intuition ------------------------------------------------%%

\subsection{Physical intuition}

In previous sections we mentioned a relation between velocity,
distance, and the meaning of integration, which provides a physical
way of thinking about integration. This section generalizes our
previous observation. The following is a restatement of the
Fundamental Theorem of Calculus in terms of net change.

\begin{theorem}
\textbf{Net change theorem.}
\index{net change theorem}
The definite integral of the rate of change $f'(x)$ of some quantity
$f(x)$ is the net change in that quantity:
\[
\int_{a}^b f'(x) \, dx = f(b) - f(a).
\]
\end{theorem}

For example, if $p(t)$ is the population of your hometown at time $t$,
then $p'(t)$ is the rate of change. If $p'(t)$ is positive then your
hometown is growing. The net change interpretation of integration is
that
\[
\int_{t_1}^{t_2} p'(t) \, dt
=
p(t_2) - p(t_1)
=
\text{change in number of residents from time $t_1$ to $t_2$}.
\]

Another very common example is in problems involving water flowing
into or out of something. If the volume of water in your bathtub is
$V(t)$ gallons at time $t$ (in seconds), then the rate at which your
tub is draining is $V'(t)$ gallons per second. If you have the
geekiest drain imaginable, it prints out the drainage rate
$V'(t)$. You can use that printout to determine how much water drained
out from time $t_1$ to $t_2$:
\[
\int_{t_1}^{t_2} V'(t) \, dt
=
\text{water that drained out from time $t_1$ to $t_2$}.
\]

Some problems will try to confuse you with different notions of
change. A standard example is that if a car has velocity $v(t)$ and
you drive forward, then slam it in reverse, and drive backward to
where you started (say 10 seconds total elapse), then $v(t)$ is
positive some of the time and negative some of the time. The integral
$\int_0^{10} v(t) \, dt$ is not the total distance registered
on your odometer, since $v(t)$ is partly positive and partly negative.
If you want to express how far you actually drove going back and
forth, compute $\int_0^{10} |v(t)| \, dt$. The following example
emphasizes this distinction:

\begin{example}
A bug is pacing back and forth, and has velocity
$v(t) = t^2 - 2t - 8$. Compute
%
\begin{itemize}
\item[(1)] the \emph{displacement} of the bug from time $t = 1$ until
  time $t = 6$ (i.e. how far the bug is at time $6$ from where it was
  at time $1$); and

\item[(2)] the \emph{total distance} the bug paced from time $t = 1$
  to $t = 6$.
\end{itemize}
\end{example}

\begin{proof}[Solution]
For~(1), we compute
\[
\int_1^6 (t^2 - 2t - 8) \, dt
=
\left[ \frac{1}{3} t^3 - t^2 - 8t \right]_1^6
=
-\frac{10}{3}.
\]
For~(2), we compute the integral of $|v(t)|$:
\[
\int_1^6 |t^2 - 2t - 8| \, dt
=
\left[ -\left( \frac{1}{3} t^3 - t^2 - 8t \right) \right]_1^4 +
\left[ \frac{1}{3} t^3 - t^2 - 8t \right]_4^6
=
18 + \frac{44}{3}
\]
which simplifies to $98/3$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Problems ----------------------------------------------------------%%

\subsection{Problems}

\begin{enumerate}
\item Two objects $A$ and $B$ start from the same location and travel
  along the same path with velocities $v_A(t) = t + 3$ and
  $v_B(t) = t^24t + 3$ meters per second. How far ahead is $A$ after 3
  seconds? After 5 seconds?

\item Sketch the graph of each function and find the area between the
  graphs of $f(x) = x^2 + 3$, $g(x) = 1$ and $-1 \leq x \leq 2$.

\item Sketch the graph of each function and find the area between the
  graphs of $f(x) = x^2 + 3$, $g(x) = 1 + x$ and $0 \leq x \leq 3$.

\item Sketch the graph of each function and find the area between the
  graphs of $f(x) = x^2$, $g(x) = x$ and $0 \leq x \leq 2$.

\item Sketch the graph of each function and find the area between the
  graphs of $f(x) = x + 1$, $g(x) = \cos(x)$ and $0 \leq x \leq \pi/4$.

\item Let $f(t)$ denote the velocity of a bug traveling along a line
  at time $t$, as shown in
  Figure~\ref{fig:integral:velocity_bug_A}. Compute the distance
  traveled in the first $4$ seconds.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (4.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,2.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
\draw[linestyle] (4,-0.1) node[below]{4} -- (4,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
% graph of function
\draw[linestyle] (0,2) -- (1,2) -- (2,1) -- (3,2) -- (4.4,2);
% dash lines
\draw[linestyle,dash pattern=on 2pt off 2pt] (1,0) -- (1,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (2,0) -- (2,1);
\draw[linestyle,dash pattern=on 2pt off 2pt] (3,0) -- (3,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (4,0) -- (4,2);
\draw[linestyle,dash pattern=on 2pt off 2pt] (0,1) -- (4.4,1);
% label
\node () at (2,2.3) [] {$y = f(t)$};
\end{tikzpicture}
\caption{Velocity of a bug at time $t$.}
\label{fig:integral:velocity_bug_A}
\end{figure}

\item Let $f(t)$ denote the velocity of a bug traveling along a line
  at time $t$, as shown in
  Figure~\ref{fig:integral:velocity_of_bug_B}. Compute the distance
  traveled in the first $4$ seconds.

\begin{figure}[!htbp]
\centering
\begin{tikzpicture}
[linestyle/.style={semithick},%
  axisstyle/.style={semithick,->,>=stealth}]
% horizontal and vertical axes
\draw[axisstyle] (-0.25,0) -- (4.5,0) node[right]{$t$};
\draw[axisstyle] (0,-0.25) -- (0,2.5) node[above]{$y$};
% tick marks on horizontal axis
\draw[linestyle] (1,-0.1) node[below]{1} -- (1,0.1);
\draw[linestyle] (2,-0.1) node[below]{2} -- (2,0.1);
\draw[linestyle] (3,-0.1) node[below]{3} -- (3,0.1);
\draw[linestyle] (4,-0.1) node[below]{4} -- (4,0.1);
% tick marks on vertical axis
\draw[linestyle] (-0.1,1) node[left]{1} -- (0.1,1);
\draw[linestyle] (-0.1,2) node[left]{2} -- (0.1,2);
% graph of function
\draw[linestyle] (0,0) -- (2,2) -- (3,2) -- (4.4,0.5);
% label
\node () at (2.5,2.4) [] {$y = f(t)$};
\end{tikzpicture}
\caption{Velocity of a bug at time $t$.}
\label{fig:integral:velocity_of_bug_B}
\end{figure}

\end{enumerate}


%%-----------------------------------------------------------------------%%
%%--- Substitution and symmetry -----------------------------------------%%

\section{Substitution and symmetry}

Let $v(t)$ be the velocity of an object at time $t$. Then the
\emph{total distance traveled} is $\int_{t_1}^{t_2} |v(t)| \, dt$ since
$|v(t)|$ is the rate of change of
\[
F(t) = \text{distance traveled}
\]
(your speedometer displays the rate of change of your
odometer). Having expressed the problem of computing the total
distance in terms of an integral, the next problem is to find
techniques for computing $\int_a^b |f(x)| \, dx$. We can proceed as
follows:
%
\begin{enumerate}
\item Find the zeros of $f(x)$ on $[a, b]$ and use these to break the
  interval up into subintervals on which $f(x)$ is always $\geq 0$ or
  always $\leq 0$.

\item On the intervals where $f(x) \geq 0$, compute the integral of
  $f$. On the intervals where $f(x) \leq 0$, compute the integral of
  $-f$.

\item The sum of the above integrals on the specified intervals is
  $\int |f(x)| \, dx$.
\end{enumerate}
%
This section is primarily about a powerful technique for computing
definite and indefinite integrals.


%%-----------------------------------------------------------------------%%
%%--- The substitution rule ---------------------------------------------%%

\subsection{The substitution rule}
\index{substitution rule}

In differential calculus, you learned numerous methods for computing
derivatives of functions. For example, the
\emph{power rule}\index{power rule} asserts that
\[
(x^a)' = a \cdot x^{a-1}.
\]
We can turn this into a way to compute certain integrals:
\[
\int x^a \, dx
=
\frac{1}{a+1} x^{a+1} \qquad \text{if $a \neq -1$}.
\]
Just as with the power rule, many other rules and results that you
already know yield \emph{techniques} for integration. In general,
integration is potentially much trickier than differentiation because
it is often not obvious which technique to use, or even how to use it.
Integration can be more exciting than differentiation!

Recall the \emph{chain rule}, which asserts that\index{chain rule}
\[
\frac{d}{dx} f(g(x)) = f'(g(x)) g'(x).
\]
We turn this into a technique for integration as follows:

\begin{proposition}
\label{prop:integral:substitution_rule}
\textbf{Substitution rule.}
Let $u = g(x)$, where $g(x)$ is a differentiable function whose range
is an interval on which $f$ is continuous. Then
\[
\int f(g(x)) g'(x) \, dx = \int f(u) \, du.
\]
\end{proposition}

\begin{proof}
Since $f$ is continuous on the range of $g$,
Theorem~\ref{thm:integral:antiderivatives_exist}~(the Fundamental
Theorem of Calculus) implies that there is a function $F$ such that
$F'= f$. Then
%
\begin{align*}
\int f(g(x)) g'(x) \, dx
&= \int F'(g(x)) g'(x) \, dx \\
&= \int \left( \frac{d}{dx} F(g(x)) \right) \, dx \\
&= F(g(x)) + C \\
&= F(u) + C \\
&= \int F'(u) \, du \\
&= \int f(u) \, du
\end{align*}
%
as required.
\end{proof}

If $u = g(x)$ then $du = g'(x) dx$. In this case, the substitution
rule simply says if you let $u = g(x)$ formally in the integral
everywhere, what you naturally would hope to be true based on the
notation actually is true.  The substitution rule illustrates how the
notation Leibniz\index{Leibniz, Gottfried Wilhelm} invented for
calculus is \emph{incredibly brilliant}. It is said that Leibniz would
often spend days just trying to find the right notation for a
concept. He succeeded.

As with all of calculus, the best way to start to get your head around
a new concept is to see several clearly worked out examples. (And
the best way to actually be able to use the new idea is to \emph{do}
lots of problems yourself!) This section presents examples that
illustrate how to apply the substitution rule to compute indefinite
integrals.

\begin{example}
Use the substitution rule to compute the integral
\[
\int x^2(x^3 + 5)^9 \, dx.
\]
\end{example}

\begin{proof}[Solution]
Let $u = x^3 +5$. Then $du = 3x^2 dx$, hence $dx = du/(3x^2)$. Now
substitute it all in:
\[
\int x^2 (x^3 + 5)^9 \, dx
=
\int \frac{1}{3} u^9 \, du
=
\frac{1}{30} u^{10}
=
\frac{1}{30}(x^3 + 5)^{10}.
\]
There is no point in expanding this out: ``only simplify for a
\emph{purpose}!''
\end{proof}

\begin{example}
Use the substitution rule to compute the integral
\[
\int \frac{e^x}{1+e^x} \, dx.
\]
\end{example}

\begin{proof}[Solution]
Substitute $u = 1 + e^x$. Then $du = e^x dx$ and the integral above
becomes
\[
\int \frac{du}{u}
=
\ln|u|
=
\ln|1 + e^x|
=
\ln(1+e^x).
\]
Note that the absolute values are not needed, since $1 + e^x > 0$ for
all $x$.
\end{proof}

\begin{example}
Use the substitution rule to compute the integral
\[
\int \frac{x^2}{\sqrt{1 - x}} \, dx.
\]
\end{example}

\begin{proof}[Solution]
Keeping in mind the power rule, we make the substitution $u = 1-x$.
Then $du = -dx$. Noting that $x = 1 - u$ by solving for $x$ in
$u = 1 - x$, we see that the above integral becomes
%
\begin{align*}
\int - \frac{(1-u)^2}{\sqrt{u}} \, du
&= -\int \frac{1 - 2u + u^2}{u^{1/2}} \, du \\
&= -\int u^{-1/2} - 2u^{1/2} + u^{3/2} \, du \\
&= -\left( 2u^{1/2} - \frac{4}{3} u^{3/2}  + \frac{2}{5} u^{5/2} \right) \\
&= -2(1-x)^{1/2} + \frac{4}{3}(1-x)^{3/2} - \frac{2}{5} (1-x)^{5/2}
\end{align*}
as required.
\end{proof}

The steps of the ``change of variable'' method can be summarized as
follows:
%
\begin{enumerate}
\item Set a new variable, say $u$, equal to some function of the
  original variable $x$ (usually $u$ is set equal to some part of the
  original integrand function).

\item Calculate the differential $du$ as a function of $dx$.

\item Rewrite the original integral in terms of $u$ and $du$.

\item Integrate the new integral to get an answer in terms of $u$.

\item Replace the $u$ in the result to get an answer in terms of the
  original variable.
\end{enumerate}
%
A ``rule of thumb'' for changing the variable: If part of the
integrand is a composition of functions, $f(g(x))$, then try setting
$u = g(x)$, the ``inner'' function.

\begin{example}
Select a function for $u$ for each integral and rewrite the integral
in terms of $u$ and $du$.
%
(a)\quad $\int \cos(3x) \sqrt{2 + \sin(3x)} \, dx$
\qquad
(b)\quad $\int \frac{5e^x}{2+e^x} \, dx$
\qquad
(c)\quad $\int e^x\sin(e^x) \, dx$
\end{example}

\begin{proof}[Solution]
(a) Put $u = 2 + \sin(3x)$. Then $du = 3\cos(3x) \, dx$ and the
integral becomes $\int \frac{1}{3}\sqrt{u} \, du$.

(b) Put $u = 2 + e^x$. Then $du = e^x \, dx$ and the integral
becomes $\int \frac{5}{u} \, du$.

(c) Put $u = e^x$. Then $du = e^x \, dx$ and the integral becomes
$\int \sin(u) \, du$.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Substitution and definite integrals -------------------------------%%

\subsection{Substitution and definite integrals}

Once an antiderivative in terms of $u$ is found, we have a choice of
methods:
%
\begin{itemize}
\item[(a)] Rewrite our antiderivative in terms of the original
  variable $x$. Then evaluate the antiderivative at the integration
  endpoints and subtract. Or

\item[(b)] Change the integration endpoints to values of $u$ and
  evaluate the antiderivative in terms of $u$ before subtracting.
\end{itemize}
%
If the original integral had endpoints $x = a$ and $x = b$, and
we make the substitution $u = g(x)$ and $du = g'(x )dx$, then the new
integral will have endpoints $u = g(a)$ and $u = g(b)$:
\[
\int_{x=a}^{x=b} \text{(original integrand)} \, dx
\qquad\text{becomes}\qquad
\int_{u=g(a)}^{u=g(b)} \text{(new integrand)} \, du.
\]

\begin{example}
Evaluate the definite integral
\[
\int_0^1 (3x - 1)^4 \, dx.
\]
\end{example}

\begin{proof}[Solution]
In line with the ``rule of thumb'' above, use the substitution
$u = 3x - 1$. Then $du = \frac{d}{dx}(3x - 1) dx = 3 dx$, so the
indefinite integral $\int (3x -1)^4 \, dx$ becomes
$\int \frac{1}{3}u^4 \, du = \frac{1}{15} u^5 + C$.

(a) Converting our antiderivative back to the variable $x$ and
evaluating with the original endpoints:
\[
\int_0^1 (3x - 1)^4 \, dx
=
\left.\left( \frac{1}{15} (3x - 1)^5 + C \right)\right|_0^1
=
\frac{32}{15} - \frac{-1}{15}
=
\frac{11}{5}
=
2.2.
\]

(b) Converting the integration endpoints to values of $u$: When
$x = 0$, then $u = 3x - 1 = 3 \cdot 0 - 1 = - 1$. When $x = 1$, then
$u = 3x - 1 = 3 \cdot 1 - 1 = 2$ so
\[
\int_0^1 (3x -1)^4 \, dx
=
\int_{-1}^2 \frac{1}{3} u^4 \, du
=
\left.\left( \frac{1}{15} u^5 + C \right)\right|_{-1}^2
=
\frac{11}{5}
=
2.2.
\]
Both approaches typically involve about the same amount of work and
calculation. Of course, these approaches lead to the same numerical
answer by the substitution
rule~(Proposition~\ref{prop:integral:substitution_rule}).

Here is how to do this using \sage. Note that the area under the two
curves $y = (3x - 1)^4$, $0 < x < 1$, and $y = x^4 / 3$, $-1 < x < 2$, are
the same:
%
\begin{center}
\fontsize{10pt}{10pt}
\selectfont
\tt
\begin{lstlisting}
sage: x, u = var("x, u")
sage: integral((3*x - 1)^4, x, 0, 1)
11/5
sage: integral(u^4/3, u, -1, 2)
11/5
sage: P = plot((3*x - 1)^4, x, 0, 1, rgbcolor=(0.7,0.1,0.5), plot_points=40)
sage: Q = plot(u^4/3, u, -1, 2, linestyle=":")
sage: R = text("$y = (3x - 1)^4$", (1.2,12))
sage: S = text("$y = x^4 / 3$", (1.5,4))
sage: plot(P + Q + R + S)
\end{lstlisting}
\end{center}
%
The plot is shown in Figure~\ref{fig:integral:plot_quartic_functions}.
\end{proof}

\begin{figure}[!htbp]
\centering
\includegraphics[scale=0.8]{image/quartic-functions.eps}
\caption{Plots of $y = (3x - 1)^4$ and $y = x^4 / 3$.}
\label{fig:integral:plot_quartic_functions}
\end{figure}


%%-----------------------------------------------------------------------%%
%%--- Symmetry and definite integrals -----------------------------------%%

\subsection{Symmetry and definite integrals}

An \emph{odd function}\index{odd function} is a function $f(x)$
(defined for all reals) such that $f(-x) = -f(x)$. An
\emph{even function}\index{even function} one for which
$f(-x) = f(x)$. If $f$ is an odd function, then for any $a$, we have
\[
\int_{-a}^a f(x) \, dx = 0.
\]
If $f$ is an even function, then for any $a$,
\[
\int_{-a}^a f(x) \, dx
=
2 \int_{0}^a f(x) \, dx.
\]
Both statements are clear if we view integrals as computing the signed
area between the graph of $f(x)$ and the $x$-axis.

\begin{example}
Integral the even function $y = x^2$ and the odd function $y = x^3$
within the interval $[-1, 1]$.
\end{example}

\begin{proof}[Solution]
The integral of $y = x^2$ for $x \in [-1, 1]$ is
\[
\int_{-1}^1 x^2 \, dx
=
2 \int_{0}^1 x^2 \, dx
=
2 \left[ \frac{1}{3} x^3 \right]_{0}^1
=
\frac{2}{3}.
\]
The integral of $y = x^3$ for $x \in [-1, 1]$ is
\[
\int_{-1}^1 x^3 \, dx
=
\left[ \frac{1}{4} x^4 \right]_{-1}^1
=
0.
\]
These computations are consistent with the symmetry (or
``anti-symmetry'') of the graphs and what you know about the
relationship between the integral and area.
\end{proof}


%%-----------------------------------------------------------------------%%
%%--- Problems ----------------------------------------------------------%%

\subsection{Problems}

For the problems below, let $f(x) = x^2$ and $g(x) = x$ and verify the
statement of non-equality.

\begin{enumerate}
\item
$\int f(x) \cdot g(x) \, dx \neq \int f(x) \, dx \cdot \int g(x) \, dx$

\item
$\int f(x)/ g(x) \, dx \neq \left.\int f(x) \, dx \right/ \int g(x) \, dx$

\item
$\sqrt{\int f(x) \, dx} \neq \int \sqrt{f(x)} \, dx$

\item
$\frac{1}{\int f(x) \, dx} \neq \int \frac{1}{f(x)} \, dx$
\end{enumerate}
%
For the following problems, compute the integral using substitution.
%
\begin{enumerate}
\addtocounter{enumi}{4}
\item
$\int \cos(3x) \, dx, \quad u = 3x$

\item
$\int \sin(7x) \, dx, \quad u = 7x$

\item
$\int e^{5x} \, dx, \quad u = 5x$

\item
$\int e^{3x} + \cos(2x) \, dx,$ \quad $u = 3x$ and $u = 2x$
\end{enumerate}
